File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes compiling problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compiling problem" Watch "compiling problem" New topic

compiling problem

Susobhan Dutta

Joined: Jul 29, 2012
Posts: 1

how to compile from the first chapter of Head First Servlets And jsp.
i am not able to under stand %javac -classpath /your path/tomcat/common/lib/serlet-api.jar -d classes src/ command
where shall i execute this command. waht is the /your path
Louis Bros
Ranch Hand

Joined: Jun 03, 2011
Posts: 54

Usually you'd run this command from within the WEB-INF directory since that's where you'll find the 'classes' and 'src' directories.

The -classpath or -cp flag is used to specify where to find class files you need while compiling. In this case you need class files that are stored in the tomcat lib jars. It is the absolute path to the tomcat lib directory.

vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 81

You need to have all Servlet container related libraries in the classpath
Scott Buckner

Joined: Jun 11, 2012
Posts: 1
Hi Susobhan,

I just recently purchased Head First Java Servlets & JSP, and completed this exercise not too long ago. This is my first-ever post on Javaranch. Hopefully what follows will help you (or whomever else reads this) make progress, without denying you the satisfaction of finally figuring it out for yourself.

I'm running Tomcat 6.0 on a Windows 7 workstation. My HeadFirst Java Projects live in c:\JavaProjects, and this exercise lives in c:\JavaProjects\HeadFirstServletsJSP\project1. I also used the environment variable %CATALINA_HOME%, which points to the base path of the Tomcat installation. In my case it's C:\Program Files\Apache Software Foundation\Tomcat 6.0. So, to compile, after completing steps 1 - 4 in the book, I used the following commands for step 5:

cd c:\JavaProjects\HeadFirstServletsJSP\project1
javac -cp "%CATALINA_HOME%\lib\servlet-api.jar" -d classes src/

Note the use of quotation marks around the classpath argument, since my Tomcat installation base path contains embedded spaces. After copying the files as described in step 6, since I'm not running Linux I instead used the service console command to start the Tomcat service: sc start tomcat6.

When I first launched a browser and pointed to http://localhost:8080/ch1/Serv1, I got a HTTP 404 error.

After carefully proofreading the deployment descriptor I typed in, it turned out instead that when I created the WEB-INF folder under the webapps/ch1 directory, I wasn't paying enough attention to what I was typing. I held the shift key down when typing the "-", and instead ended up with WEB_INF. After a frustrating period of time, I finally found my typo. Once changed, everything worked fine.

You can also use the service console commands sc stop tomcat6, and sc query tomcat6 to stop Tomcat and find out whether Tomcat is running, respectively.

When you get to the beerV1 project you will need to modify the -cp and -d arguments. The book explains what to do, but read (and type) carefully. I wish you success with your efforts!
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46367
Welcome to the Ranch

It goes to show how a tiny spelling error can throw things totally. Well done finding it.
I agree. Here's the link:
subject: compiling problem
It's not a secret anymore!