Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Errors while javac help.....

Status
Not open for further replies.

zhixiong

Programmer
Jan 13, 2003
13
0
0
SG
When i javac a java file, the following errors came out.
C:\>javac logon.java
logon.java:3: package javax.servlet does not exist
import javax.servlet.*;
^

logon.java:4: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
2 errors

Anyone knows what does it means???


 
It's a classpath issue. The
Code:
javax.servlet.*
packages are not part of the default J2SE installation.

Rather these packages come bundled with your appserver, and the classpath it uses internally "sees" these packages, wheras the classpath javac uses (run from the cmd line) doesn't "see" these packages.

So you just need to add the servlet packages to your classpath. If you use Tomcat the part you need to add should look like this:
Code:
$TOMCAT_HOME/common/lib/servlet.jar
or just run javac with a -classpath arg like this:
Code:
javac foo.java -classpath $TOMCAT_HOME/common/lib/servlet.jar
where $TOMCAT_HOME is the path to tomcat's main dir
Hope this helps,
petey
 
I typed:

javac logon.java -classpath $TOMCAT_HOME/common/lib/servlet.jar


at the command prompt, but the same errors came out.

Regarding to your reply:
The part that I need to add should look like this:

$TOMCAT_HOME/common/lib/servlet.jar

Where should I add this line to??? Thanks.

 
Maybe the simplest approach is to use the Windows 'find' utility to locate servlet.jar. Suppose, for example, that you use the find utility and discover servlet.jar lives in c:\blah. Then run your javac command with that path name:

javac foo.java -classpath c:\blah\servlet.jar

Classpaths are like riding a bike. It's hard to do at first but then suddenly it all starts to make sense.

Link:
petey
 
The servlet.jar file is in c:\jakarta-tomcat-4.1.18\common\lib.
I typed: javac logon.java -classpath c:\jakarta-tomcat-4.1.18\common\lib\servlet.jar The same errors came out again... I wonder if i could contact you off-list??? Maybe in this case you are able to understand my problem much clearly.
 
Hmm... All I can tell you is double-check the location of servlet.jar and double-check the spelling and try again. I can't help beyond that unless I actually sat at your machine.

Anybody else have ideas? Am I missing anything?

petey

 
Is it possible for me to send you the file, so when you sees it you can clearly tell me where to put these files to. The files are examples that i downloaded from the net, I just wanted to know how it works so as to learn from it.
 
Well, I could look at the file, but this is a very well known and common error that every servlet developer runs into at least once, and the solution is always the same.

Are you compiling this file on the same machine that your server runs on?

petey
 
Yes I am compiling this file on the same machine. It is actually an example which I wanted to run it and see what it does. If its possible that i could sent you the file then the problem will be solve and you will be able to understand it much clearly. If you agree then how do I sent you the file?
 
The problem is simple, the solution is simple, and I already understand this quite clearly, you don't need to send me any files. (I don't open attachments anyway) [upsidedown]

You are trying to compile code that depends on code within servlet.jar. You therefore need to put servlet.jar in your classpath. If you try that and the exact same errors appear, then there's a typo or misspelling somewhere in your javac command.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top