• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet compilation error.

 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the same old problem of Servlet Classpath settings.Someone please help.

I use Apache Tomcat4.1,j2sdk1.4.2_08 on windows XP.
I am able to do the foll ,
1.See the Apache Tomcat/4.1.31 homepage and execute the examples of that.
2.Compile all other java files.
3.execute simple JSP examples like date display etc.
but unable to compile servlets.

I set the path and classpath in Environment Variables(XP).
path=C:\Sun\AppServer\bin;C:\j2sdk1.4.2_08\bin;C:\program files\apache group\tomcat4.1\Common\lib\Servlet.jar
CLASSPATH=.;C:\Sun\AppServer\bin;C:\j2sdk1.4.2_08\bin;C:\program files\apache group\tomcat4.1\Common\lib\Servlet.jar

but still I get
javax.servlet does not exist.

I am sure that am missing some simple step,please help me out
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you don't need to put jar files in your system path or bin directories in your classpath. Doing so just makes it harder to debug these types of issues.

Try just putting servlet.jar (watch case) on your classpath.
Also, I know that, with at least some versions of Windows, you need to wrap your classpath/path env variables with quotes if there are spaces in the directory names.
 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help.
I have done the mentioned changes, but still the problem persists even after restart,
Now my path and classpath are,

CLASSPATH="C:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar"

path=C:\Sun\AppServer\bin;C:\j2sdk1.4.2_08\bin;

The path on which servlet.jar resides ac copied from its properties is,
C:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar

Please help
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Visit this link Tomcat Configuration

bye for now
sat
 
Sharad Agarwal
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a first step, try specifying the CLASSPATH explicitly in the javac command:

javac -classpath "C:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar" <yourServlet>.java
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I do all servlet compiling through ANT because I can use the build.xml file to define the exact classpath needed for any particular project on the fly. My system environment variables stay clean and I can switch projects without any chance of confusion between library versions. Yes there is a learning curve but well worth the effort.
(Plus, of course, major open source Java toolkits ship with build.xml files included.)
Bill
 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a first step, try specifying the CLASSPATH explicitly in the javac command:

javac -classpath "C:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar" <yourServlet>.java


I have tried and it doesnt help.But the example servlets in Tomcat seem to work fine.I am damn sure am missing something very silly but could not figure out.PLEASE HELP
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried and it doesnt help. But the example servlets in Tomcat seem to work fine. I am damn sure am missing something very silly but could not figure out.


Wait.
What doesn't work?
Are you trying to compile or run a servlet?
The classpath has nothing to do with running servlets.
Tomcat ignores your classpath.

You DO need servlet-api.jar on your class path to compile your servlet.

What are you trying to do that isn't working?
 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am trying to compile the servlet and not run the servlet. In the lib file I just find a servlet.jar file and not servlet-api.jar.I use Tomcat4.1.
Do I have to download a Servlet-api.jar file from somewhere apart from the
normal installation of tomcat..??

Sorry for getting confused between running and compiling and also confusing you.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, servlet.jar is fine (my mistake there).
What errors are you getting when you try to compile your servlet with that classpath?
 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the error I get is ,package javax.servlet does not exist.
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Servlet.jar is not in the Classpath. Check again.

or check my previous answer and read the article how to install & configure tomcat

bye for now
sat
 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My current classpath as copies from the CLASSPATH variable is as follows,

[<B>] CLASSPATH= .;"C:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar" [</B>]

if you refer to the reply to Ben Souther .My classpath does have servlet.jar file.I havent change my settings yet.Only change I have made to it after that is to add a . to include currentdirectory.

The link you gave does give info abt Configuring Tomcat and deploying
webapplication.Am not able to relate it to servlet compilation.My tomcat
is working fine and even samples are working fine.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you've got should work.

Here's one way to triple check your classpath.

1.) From the command line, type:
echo %CLASSPATH% > MYCP.txt

2.) Open MYCP.txt with notepad and copy the part of the classpath
that points to the common/lib directory.

3.) Open Explorer and paste the path into the address field.

Explorer should be pointing to the directory with the jars.
You should see servlet.jar in there.
 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben, It does point to the dirctory where servlet.jar file is present.
I have a doubt with the sample am code am testing with,
please hav a look,
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class helloworld extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}

I am using javac helloworld.java to compile
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what error are you seeing when you try to compile it?


PS: It's always a good idea to stick to Java naming conventions.
Classnames should start with an upper case letter (Helloworld.java).
 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the error
helloworld.java:2 : p ackage javax.servlet does not exist
import javax.servlet.*;
helloworld.java:3 : p ackage javax.servlet.http.*; does not exist
import javax.servlet.http.*;

etc...

Even the javap javax.servlet.http.HTTPServlet; does not work
ERROR:could not find javax.servlet.http.HTTPServlet;

I have tried unistalling and reinstalling TOMCAT but still doesnt work.

please suggest any other server to learn servlets..
[ July 24, 2005: Message edited by: yash Vi ]
 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
: and p together has given a smiley .. please replace the smiley with
: p while reading
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by yash Vi:
: and p together has given a smiley .. please replace the smiley with
: p while reading



You can edit your post - use the icon that looks like a paper and pencil. Put a space in to prevent the smiley. Or select the box right at the bottom of the input form (Scroll down and check "Disable smilies in this post").
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi yashvi


I am sure your jar file is not in the classpath. So that you are getting the same error. Tomcat is simple to configure and learn servlets.
your code is correct. verify the configuration of Tomcat again

bye for now
sat
 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have checked it and the classpath in my previous reply was copied from the environment variable-> classpath-> edit and hence i feel that there is not a possibility of typo too.I followed wot ben adviced and cud view the
directory of the jar files..Is there anything else to be done apart from classpath....
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Your class path is
[<B>] CLASSPATH= .;"C:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar" [</B>]



But no
servlet-api.jar in your classpath. Change from servlet.jar to servlet-api.jar in your classpath.
your classpath should be like this


I hope, now it will work.
bye for now
sat
 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,I amusing tomcat4.1 and there is no sevlet-api.jar in the lib only servlet.jar is present.As discussed with ben earlier ,shd I dowload this servlet-api.jar.?
 
chsanthosh kumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please servlet-api.jar

Download it from here.
 
Stefan Evans
Bartender
Posts: 1784
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to download it. Use the one in [TOMCAT_HOME]/common/lib

In Tomcat4 it was servlet.jar
In Tomcat5 the split it into servlet-api.jar and jsp-api.jar

Try moving it into a directory that doesn't contain spaces in it.
ie copy it to C:\java\servlet.jar, add that to your classpath and try compiling again
 
samdeep aarzoo
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey i m also getting same problem as same that of yash
javax.servlet does not exist

i already set path and classpath

yash now do u able to compile servlet
 
samdeep aarzoo
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry guys my servlet compiles after setting the classpath again
than restarting the machine it works
 
keris joyo
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you must download a jar file of servlet.jar into the directory where ${tomcat_home}/common/lib.if that,you will compile servlet!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic