I am using windows xp. I am compiling servlet code by using -classpath option on the command line to point to the servlet-api.jar and jsp-api.jar files in the server directory. However, putting these same paths in the CLASSPATH environment variable and not using the -classpath option on the command line fails to compile as the compiler is not seeing the jar files. What am I missing here?
Be certain that you're spelling CLASSPATH correctly, with all uppercase letters, as the environment variable.
Also, note that, if opened before changing an environment variable, a command prompt or program like Notepad won't "see" the new environment variable value, and it will use the value that was specified when the program was opened. So, just close them and re-open after changing the environment variable value.
Here is a cut and paste from the XP form for setting the system environment variables: Variable Name: CLASSPATH Variable Value: .;"C:\ServletDevel";"C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\jsp-api.jar";"C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar"
This is what I get from ECHO %CLASSPATH% .;"C:\ServletDevel";"C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\jsp-api.jar";"C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar"
I have tried compiling in a new window after the changes. All to no avail.
The same classpath above will option -classpath would compile with no problem. Its still a problem.
Joined: Dec 10, 2001
I'm surprised that you're having this problem, as your CLASSPATH setting looks correct to me, assuming that the specified paths are correct, of course.
Do things compile with the following command?
javac -classpath %CLASSPATH% Foo.java
Just for fun, you might want to try putting your needed JARs in a path with no spaces in the name, setting the CLASSPATH accordingly, and see if things compile.
Just as a bit of encouragement, I've never seen a computer system where Java could not be successfully installed with the CLASSPATH environment variable configured and working. So, don't give up. There's likely just some small thing that's configured incorrectly.