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

javax.servlet not found

 
Abhinav Pandey
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers i am very new to servlets. I have jdk1.5 installed in my pc
along with Sun Studio EnterpriseEdition
Whenever i try to compile my code (having import javax.servlet.*) from command prompt, it gives a compiler error of above package not found. Whereas my normal corejava codes compiles fine.Kindly tell me how to get the package in the path
 
Dinuka Arsakularatne
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to install tomcat5.0 and j2ee 1.5 sdk as well. then set the eviroment variables as follows; (note that this is relative to where i have installed the relevant applications)

ANT_HOME - C:\Sun\AppServer\lib\ant
CLASSPATH - .;C:\apache-tomcat-5.5.17\apache-tomcat-5.5.17\common\lib\servlet-api.jar;C:\apache-tomcat-5.5.17\apache-tomcat-5.5.17\common\lib\jsp-api.jar;

J2EE_HOME - C:\Sun(where you install the j2ee sdk)
JAVA_HOME - C:\Sun\AppServer\jdk(where you have installed the j2se jdk)
PATH - "C:\Sun\AppServer\bin";"C:\Sun\AppServer\jdk\bin";"C:\Sun\AppServer\lib\ant\bin";%PATH%
thats about it... after that just compile your code from the command promt and check... hope this helped.
 
bhagavatula indu sekhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think the edition you are using doesn't contain classes which are necessary for servlets.

download jsdk2.1 and set

On windows system :

classpath to rootdirectory:\jsdk2.1\servlet.jar;rootdirectory:\jsdk2.1\server.jar

Example : classpath is D:\jsdk2.1\servlet.jar;D:\jsdk2.1\server.jar;
classpath is an user defined environment variable.
if it is not present then create it.

now after setting this compile your servlet.i think it must work.

i think i answered your question properly and this is the first reply for a question in this community.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Abhinav Pandey:
Hello ranchers i am very new to servlets. I have jdk1.5 installed in my pc
along with Sun Studio EnterpriseEdition
Whenever i try to compile my code (having import javax.servlet.*) from command prompt, it gives a compiler error of above package not found. Whereas my normal corejava codes compiles fine.Kindly tell me how to get the package in the path


All you need is your servlet library on your classpath. Typically servlet.jar or servlet-api.jar.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by bhagavatula indu sekhar:
download jsdk2.1


??

Moreover, SDK doesn't, typically, include servlet library.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adeel Ansari:
Moreover, SDK doesn't, typically, include servlet library.


JSDK -as opposed to the any of the Java SE/EE SDKs- used to be short for "Java Servlet Dev Kit", and it did include the jar files. But the term JSDK was dropped a while ago. The servlet jars are now available here, or as part of a Tomcat installation.
[ November 08, 2006: Message edited by: Ulf Dittmer ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See:
http://faq.javaranch.com/view?CompilingServlets

Moving to Java In General where javac and classpath issues are discussed.
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to add [Java EE directory]\lib\javaee.jar to your classpath variable.

If you are still using J2EE instead of Java EE 5, you need to add [J2EE directory]\lib\j2ee.jar to your classpath.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic