This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
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

compiling a servlet

 
Sammy vemu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

When iam trying to compile a servlet class which is in D:\jsdk1.3.1 directory
iam getting following errors:

package javax.servlet not found in import
package javax.servlet.http not found in import
superclass HttpServlet of class helloworld not found.
I set the environment variables in my Win 2000 O/S as follows:
classpath $TOMCAT_HOME\common\lib\servlet.jar
TOMCAT_HOME D:\jakartha_tomcat
JAVA_HOME D:\jsdk1.3.1
I dont see any of servlet packages in my jsdk or in tomcat.
where should i see for servlet packages?
I think i missed some of the settings.
Whatelse i need to add to my settings expalin with example,please...
Waitng for reply
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These classes are in the servlet.jar file in the Tomcat library. It sounds like your classpath is not set correctly.
I think you have mis-spelt 'Jakarta' on the definition of the TOMCAT_HOME environment variable.
HTH
 
Sammy vemu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andy,
I renamed the original tomcat directory,i think its ok to rename the directory ...
Can you please tell me the actual problem..
really iam trying hard to get this problem solved..
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Sammy, it looks like your are having a little problem compiling, huh. Well I had the same problem as most of us had at one time or another.
The first thing I would do as Andy pointed is to make sure your environment variables are pointing to valid directories and or files. Second, based on what you environment is:
classpath$TOMCAT_HOME\common\lib\servlet.jar
TOMCAT_HOME D:\jakartha_tomcat
JAVA_HOME D:\jsdk1.3.1

It looks like you are defining %classpath% using %tomcat_home%. But you do not define %tomcat_home% until the next line, so it is possible that %classpath% contains only \common\lib\servlet.jar, not what you intended.
Another thing, if you decide to define %classpath%, define it this way
(by the way I am using w95 operating system)
classpath = %tomcat_home%\lib\servlet.jar;.
Don't forget the semi-colon and period at the end.
The period says use your PWD(present working directory) as part of your classpath.
Hopefully, that should solve your problem. But there are other alternatives:
1. You can download the j2sdkee and place the path %j2ee_home%\lib\j2ee.jar as part of your classpath environment.
2. Place a copy of the servlet.jar or j2ee.jar in the %java_home%\jre\lib\ext directory and you will not need to set the classpath variable.
3. Include the classpath at compile time for example:
javac -classpath %j2ee_home%\lib\j2ee.jar;. Source.java
I like using the j2ee.jar because If I need any enterprise package other than servlet/jsp, I know it will be in the j2ee.jar file.
I hope this helps.
cj
 
Sammy vemu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi cj,
Thanks for the reply and explination.
My O/S is win2000..so when i define the following environment variables:
classpath .;$TOMCAT_HOME\common\lib\servlet.jar
TOMCAT_HOME D:\jakarta_tomcat
JAVA_HOME D:\jsdk1.3.1
should work,bcoz,in win2000 environment variables set using controlpanel.
so there is no question of only taking \common\lib\servlet.jar even i define the classpath using tomcat-home,which is define in the nextline.It should take entire path.
And i also tried with j2ee.jar(j2sdjee).Still my servlet is not compiling..
I also copied servlet.jar to ext directory of java directory..
I like to ask what is the difeerence between TOMCAT_HOME and CATALINA_HOME?
Still iam getting the same following errors:
package javax.servlet not found in import
package javax.servlet.http not found in import
superclass HttpServlet of class helloworld not found.
Please somebody help me with this..
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If you are using window OS then you have to refere to TOMCAT_HOME or any other variable like e.g. this %TOMCAT_HOME% - the way you do it is for UNIX.
When using win NT/200/XP you can always check if the path is right by looking at the translated path in the list in 'Environment Variables'
TOMCAT_HOME is the variable used by tomcat versions less then 4
CATALINA_HOME is the variable used by tomcat 4.x. - if this variable in 4.x isn't set tomcat will still startup.
Rene
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rene is correct, unless you have a very old verion of Tomcat, you need to set your environment
variable to CATALINA_HOME instead of TOMCAT_HOME. The documentation README.txt should tell you what you need to know.
Also after you have set your environment variables and have rebooted your PC, open up a ms-dos window, so as to do a quick check to see that your environment variables were set correctly.
At the command ms-dos prompt type:
>echo %catalina_home%<nl>
>echo %java_home%<nl>
>echo %classpath%<nl>
Note: verify information is correct.
Also do this:
>cd %catalina_home%<nl>
>cd %java_home%<nl>
Note: if you get any message stating that this directory no longer exist or invalid, your variable is not set correctly.
Also did you append the %java_home%\bin variable to the %path% environment variable.
Check by typing at the ms-dos prompt:
>javac<nl>
Note: you should see the javac compiler parameter list.
Good luck, I hope this helps.
cj
 
Sammy vemu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rene & Cj
Now my servlet is compiling with out any errors.But when i tried to run the servlet it gives 404 not found error..
I started server.
I created a directory "new" in the webapps and
put the web.xml in the webapps\new\web-inf directory.And index.html in the new directory..
My classes are in \new\web-inf\classes directory.
when iam trying to access servlet using following URL:
http://localhost:8080/servlet/HelloWorld
it gives error as
The requested resource (/servlet/HelloWorld/) is not available.
How to enable the servlet invoker,which is in /conf/web.xml?
Is ther any other way to run servlet in the browser!!!
Thanks
Sammy.
 
Ivan Tamayo
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must to study how to invoke servlets in a web application.
The url you are using is for the ROOT application, and even this is wrong, because tomcat since 4.1.12 doesn�t accept the servlet/* pattern
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to enable the servlet invoker,which is in /conf/web.xml?

Well, to start.. open conf/web.xml

It turns out that this file is *heavily* commented, and it tells you how to enable the invoker servlet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic