GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Still cant complile servlet after setting classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Still cant complile servlet after setting classpath" Watch "Still cant complile servlet after setting classpath" New topic
Author

Still cant complile servlet after setting classpath

Max Vandenburg
Ranch Hand

Joined: Mar 09, 2006
Posts: 51

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


MV
Max Vandenburg
Ranch Hand

Joined: Mar 09, 2006
Posts: 51
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Max Vandenburg
Ranch Hand

Joined: Mar 09, 2006
Posts: 51
this is what i got in the CLASSPATH
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Mar 09, 2006
Posts: 51
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

Joined: Dec 15, 2005
Posts: 108
Aren't those packages/classes in the j2ee.jar file? It doesn't look like you're including that.


Mike Noel
Max Vandenburg
Ranch Hand

Joined: Mar 09, 2006
Posts: 51
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

Joined: Jan 03, 2006
Posts: 490
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.


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

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 ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Max Vandenburg
Ranch Hand

Joined: Mar 09, 2006
Posts: 51
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Still cant complile servlet after setting classpath