Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Still cant complile servlet after setting classpath

 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I dont get it!!!
Ok, im running the latest Apache Tomcat/5.5.17, and jdk1.5.0_06
I've also set up the TOMCAT_HOME and the JAVA_HOME to the following:

JAVA_HOME=C:\Program Files\Java\jdk1.5.0_06\bin
TOMCAT_HOME=C:\Program Files\Apache Software Foundation\Tomcat 5.5

and for the CLASSPATH
CLASSPATH=%CLASSPATH%;%TOMCAT_HOME%\common\lib\servlet-api.jar
the PATH is set to PATH=%PATH%;%JAVA_HOME%

when compiling my servlet by following the instruction in the Head First Servlet JSP (SelectBeer.java)

i get the same 6 error message package not found.
am i not setting the classpath correctly, but im pretty sure it is correct.
or do i also need to install the J2EE. can anyone help.

Thanks
 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i also tried to compile the SelectBeer.java using Eclipse (instead of using the command line) where i added the servlet-api.jar file to the libraries. this compiles fine and i managed to get the SelectBeer.class file --- which i then moved to:

%TOMCAT_HOME%\webapps\Beer-V1\WEB-INF\classes\com\example\web

then (did what it says on the book):
1. i restart tomcat
2. launch my browser and go to http://localhost:8088/Beer-V1/form.html
- this loads my "Beer Selection Page"
3. then the SUBMIT button is clicked... and i get err 404... which means that the servlet is not working...

can anyone spot where i make the obvious (not so obvious to me) mistake
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Firman Drage:

JAVA_HOME=C:\Program Files\Java\jdk1.5.0_06\bin
TOMCAT_HOME=C:\Program Files\Apache Software Foundation\Tomcat 5.5

and for the CLASSPATH
CLASSPATH=%CLASSPATH%;%TOMCAT_HOME%\common\lib\servlet-api.jar
the PATH is set to PATH=%PATH%;%JAVA_HOME%


The JAVA_HOME environment variable should not point to the 'bin' directory.
It should point to the root of your java installation (jdk1.5.0_6)

The PATH environment variable should point to the bin directory.
(If you're getting class not found problems during compilation then the JDK install probably took care of this for you and is allowing your OS to find javac in spite of the mistake in your PATH entry).

Have you tested your CLASSPATH variable?
Try typing:

It will print your CLASSPATH setting to the screen.
 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is what i got in the CLASSPATH
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're seeing the literal "%TOMCAT_HOME%" instead of the path to your tomcat install, then your TOMCAT_HOME environment variable is not set.

I'm going to move this to Java In General (Beginner).
A firm understanding classpaths and javac are prerequisites for efficient servlet development.
 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after system restart:



so now i know that the classpath is set correcly... i also re-check the PATH to make sure it doesnt say %JAVA_HOME% , rather the actual path where the java is installed.

then i tried to compile the servlet again

 
Mike Noel
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aren't those packages/classes in the j2ee.jar file? It doesn't look like you're including that.
 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No those are correct... because i set the classpath to include the servlet-api.jar, and they also works ... erm after i re-deploy the class file to the server side.

Thanks,
:roll:
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a hard time getting Tomcat set up properly also. Then i used this preconfigured setup, from the Author of Core servlets and JSP. Was compiling and running servlets 5 minutes later. Might be worth a try.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15435
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at this line:

javac -classpath "C:\Program Files\Apache Software Foundation\Tomcat 5.5/common/lib/servlet-api.jar:classes:." -d classes src/com/example/web/BeerSelect.java

You are using a colon ( instead of a semi-colon (;) to separate the classpath entries. That's wrong on Windows. Use a semi-colon instead.
[ July 13, 2006: Message edited by: Jesper Young ]
 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for pointing that out... after setting the CLASSPATH environment variable to include the pathXXXX\servlet-jar.api - i no longer needed the -classpath option in the javaccommand

so the cmd used was:
javac -d classes src/com/example/web/BeerSelect.java

but yes, Jesper Young, you are right to point out about the colon ( vs. semicolon ( thing.

PS: the "try" link doesnt work
Might be worth a try.


all this time compiling java files using ide i've forgotten some basic cmd line arguments
see http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html#commandlineargfile

[ July 13, 2006: Message edited by: Firman Drage ]
[ July 13, 2006: Message edited by: Firman Drage ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic