Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie question

 
Harry Kong
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to complile a simple servlet program, and the complier complains that the packages do not exsit. These two:
import javax.servlet.*;
import javax.servlet.http.*;
I've setup the CLASSPATH as:
CLASSPATH=%CLASSPATH%;C:\Tomcat4.0.1\common\lib\servlet.jar
This is according to Manning's SCWCD Study Kit book. I also setup CATALINA_HOME, JAVA_HOME, and appropriate paths. Is there more to be done? What am I doing wrong?
Thanks, Harry.
PS - I am using Windows 2000.
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure your path to the servlet.jar is correct, thats the only thing I can see that would be wrong.
 
Harry Kong
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean this line?
CLASSPATH=%CLASSPATH%;C:\Tomcat4.0.1\common\lib\servlet.jar
Or do you mean
PATH=C:\Tomcat4.0.1\common\lib\servlet.jar
Thanks.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be your classpath.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you compile, what does the command line look like?
 
Harry Kong
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I double checked and the classpath is okay.
I use regulat complie command to compile, that is:
javac Hello.java
Is there some other option I have to specifiy?
 
Dominic Paquette
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
try
javac -classpath C:\Tomcat4.0.1\common\lib\servlet.jar hello.java
Dominic
 
Harry Kong
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, no that didn't work either. Arrrgh, this is very frustrating. This should be a simple task.
 
Rich Raposa
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a CLASSPATH problem. Your CLASSPATH is not set correctly. Search your computer for servlet.jar, because it's obviously not in:
C:\Tomcat4.0.1\common\lib\
 
Harry Kong
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Classpath is correct. That's where servlet.jar is.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That should work.

If your class file is here:
c:\tomcat4.0.1\webapps\foo\foo.java

then the following command should compile the servlet:

c:\tomcat4.0.1\webapps\foo> javac -classpath .;c:\tomcat4.0.1\common\lib\servlet.jar foo.java

This assumes your servlet is not packaged.

If you type in the exact command as above (replacing 'foo' where appropriate) what is the exact error message you get back?

Also remember, java is case-sensitive, so "Foo" is different than "foo".
[ January 18, 2003: Message edited by: Mike Curwen ]
 
Harry Kong
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike, that worked! Thanks!!!
I am soooo happy!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic