Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet does not compile, again!

 
Sukrit Sulochana
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The path to servlet-api.jar must be wrong.
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler cannot find ther required servlet classes. Add its (servet.jar/j2ee.jar) location to your classpath settings.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic