wood burning stoves 2.0*
The moose likes Servlets and the fly likes Servlet does not compile, again! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet does not compile, again!" Watch "Servlet does not compile, again!" New topic
Author

Servlet does not compile, again!

Sukrit Sulochana
Greenhorn

Joined: Oct 13, 2005
Posts: 21
Hi,

I just wrote a servlet after installed the latest version of Tomcat.

When I compile the servlet I get the errors:

package javax.servlet does not exist
package javax.servlet.http does not exist

I am able to compile and run normal java programs.

My CLASSPATH variable is set as follows:

CLASSPATH=.;"C:\Program Files\Java\jdk1.5.0_06\bin"; "C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar"; "C:\Program Files\Java\j2re1.4.2_03\lib\ext\QTJava.zip"


What could be the problem?
Thanks,
Rajneesh
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

The path to servlet-api.jar must be wrong.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
The compiler cannot find ther required servlet classes. Add its (servet.jar/j2ee.jar) location to your classpath settings.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

Originally posted by Bosun Bello:
Add its (servet.jar/j2ee.jar) location to your classpath settings.


He already stated he has servlet-api.jar in his classpath. My guess is a typo or other error in the path to the jar file.
Michael Duffy
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
Originally posted by Rajneesh Joshi:
Hi,

I just wrote a servlet after installed the latest version of Tomcat.

When I compile the servlet I get the errors:

package javax.servlet does not exist
package javax.servlet.http does not exist

I am able to compile and run normal java programs.

My CLASSPATH variable is set as follows:

CLASSPATH=.;"C:\Program Files\Java\jdk1.5.0_06\bin"; "C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar"; "C:\Program Files\Java\j2re1.4.2_03\lib\ext\QTJava.zip"


What could be the problem?
Thanks,
Rajneesh


I was going to say that paths with spaces in them are usually problematic, but I see that you've got quotes around yours.

Why does the JAVA_HOME/bin appear in your CLASSPATH? That belongs in PATH.

Why does your application need that QTJava.zip archive for?

The fact that you've got a CLASSPATH suggests that this is an environment variable. I think that's the wrong way to do it. (I don't have a CLASSPATH environment variable on any machine that I use.) A single CLASSPATH doesn't apply to every application that I write. IDEs and JEE containers both ignore it completely, so I don't find it to be very useful.

Your experience suggests that the JDK compiler ignores it, too.

I think the right way to do it is to use the -classpath option for javac.exe. That guarantees that you'll have everything you need when you compile:



%
 
jQuery in Action, 2nd edition
 
subject: Servlet does not compile, again!
 
Similar Threads
Issues Compiling With Javac
Compile problem not finding package javax.servlet.http
package apache.commons not exists
package javax.servlet does not exist
error in servlet compile