• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

compiling problem

 
Greenhorn
Posts: 1
Opera Redhat Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to compile Ch1Servlet.java 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/Ch1Servlet.java command
where shall i execute this command. waht is the /your path
 
Ranch Hand
Posts: 54
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 83
Netbeans IDE MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to have all Servlet container related libraries in the classpath
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 Ch1Servlet.java, 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/Ch1Servlet.java

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!
 
Marshal
Posts: 79699
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

It goes to show how a tiny spelling error can throw things totally. Well done finding it.
 
Look! It's Leonardo da Vinci! And he brought a tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic