Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · ASP.NET Newsletter Application · Web Hosting Plans · Faisal Khan's Blog · Contact
Forums : J2EE : JSP : compile TestServlet errors Signup · Login
Author Thread
compile TestServlet errors
Posted in tutorial: Introduction to Java Servlets, Developing your first Java Servlet
·  hungmusic
User
Joined: 21 Nov 2002
Total Posts: 3

compile TestServlet errors

Posted: 22 Nov 2002
Hi,

I am just a newbie of jsp. After i type javac TestServlet.java and hit enter, it displays 11 erros. But i think the first two errors are the cause and they are displayed like this:
TestServlet.java:7: package javax.servlet does not exist
TestServlet.java:7: package javax.servlet.http does not exist

Can I get help for this problem? Thanks a lot.

Newbie
·  Faisal Khan
AdminAdminAdminAdmin
Joined: 24 Sep 2002
Total Posts: 594
Re: compile TestServlet errors
Posted: 22 Nov 2002
It'd have been very useful for you had you first learned and understood the basics of Java ( language) before delving yourself into more advanced topics.

Anyway, the reason you are getting this error is because the Java compiler ( javac ) cannot find the JAR files containing the class files for the packages that you have mentioned. Now there are two solutions to this problem:

1. Every Servlet container makes available a JAR file which contains these packages e.g. J2EE 1.3.1 reference implementation contains these packages inside a JAR file called 'j2ee.jar' present in the 'lib' folder.

To know what JAR file of your Servlet container contains these packages, either check the documentation or look for similarly named JAR files in it's 'lib' folder.

Suppose you searched and find out that there is a 'j2ee.jar' JAR file in C:\SomeFoler\lib\ folder. To let the javac know about it you'll have to issue a command like this *every time* you want to compile this Servlet:


javac -classpath %CLASSPATH%;C:\SomeFoler\lib\j2ee.jar;. TestServlet.java

Where 'TestServlet.java' is the name of your TestServlet's source file. It'll compile the TestServlet.java source file into TestServlet.class file in the same folder.

2. Use a Servlet container like Resin ( www.caucho.com ), to develop applications. In Resin for example all you'll have to do is to place your .java source files of your Servlets, JavaBeans etc under the /WEB-INF/classes/ folder and when you access them the first time, Resin will automatically compile them for you.

When you make any changes in those source files, Resin will detect the changes and recompile them for you. It is just so helpful and will save you lot of time.

Btw I am not sure if it is possible with Tomcat, I haven't been using Tomcat lately so don't know.

Faisal Khan.
Stardeveloper.com
Read Blog | Follow on Facebook, Twitter
·  shibby1011ph
User
Joined: 20 Aug 2003
Total Posts: 7
10 errors when i compile TestServlet.java
Posted: 20 Aug 2003
i am using jsp and mysql along with jdk1.3.1_08, tomcat, redhat linux, apache for my current project. i decided to use servlets to enhance my project and make it more efficient.

however, when i compile TestServlet.java, it generates 10 errors.
one of these errors say that 'package javax.servlet' doesn't exist.
so i followed the 1st solution to this problem since i am not using resin.
i tried searching j2ee.jar but my search results turn up empty.
so i checked the documentation and this is what it says :
-----------------------------------------
Q: What do I need in my CLASSPATH?
A: All you need is a correct version of JDK (1.1.x or 1.2).
Since the JSP engine also uses 'javac' it needs to be in the CLASSPATH.
If you are using JDK 1.1.x it will automatically be included. If
you are using JDK 1.2 you will need to set JAVA_HOME to the directory
where JDK is installed or alternately you can put "tools.jar" in your
CLASSPATH.

All other classes, jar files that are needed, are put by the startserver
script and you don't need to worry about them.

Q: Where are the classes for JSPs and Servlets?

A: webserver.jar -- class files for Servlet Engine.
lib/jspengine.jar -- class files for JSP Engine.
lib/servlet.jar -- Public APIs for Servlet.
lib/jsp.jar -- Public APIs for JSP.
lib/xml.jar -- classes for parsing XML document
---------------------------------------
so i put xml.jar, servlet.jar and webserver.jar in my classpath along with tools.jar.

i tried searching for jspengine.jar and jsp.jar but my search results turn up empty. what should i do? btw, below is my classpath (if it's any help at all):

export CLASSPATH=/usr/local/jdk1.3.1_08/jre/lib/rt.jar:/usr/java/lib/tools.jar:/usr/src/jakarta/dist/tomcat/lib/servlet.jar:/usr/src/jakarta/dist/tomcat/lib/webserver.jar:/usr/src/jakarta/dist/tomcat/lib/xml.jar:

i know a bit about java like methods, events, classes but i don't know much about jars and servlets. i'm still new to them so pls don't get mad

thank u very much

Just a JSP Newbie =)
·  Faisal Khan
AdminAdminAdminAdmin
Joined: 24 Sep 2002
Total Posts: 594
Re: 10 errors when i compile TestServlet.java
Posted: 28 Oct 2007
Your question was answered in this thread: http://www.stardeveloper.com/articles/thread.html?tid=767

Faisal Khan.
Stardeveloper.com
Read Blog | Follow on Facebook, Twitter
Want to leave a comment? Login or Register for free!

Users Who Have Visited This Thread In Last 24 Hours
5 Visitors

Login to post a comment or start a new thread
UserName Or Email Address:       Password:       Auto-Login:    
· Create New User Account
· Send Forgotten Password by Email
 
© 1999 - 2010 Stardeveloper.com, All Rights Reserved.