File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How to compile servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to compile servlets" Watch "How to compile servlets" New topic

How to compile servlets

Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
Posts: 89

Are my path & classpath correct for compiling servlets?

I downloaded the J2EE1.4 s/w bundle that includes

# Sun Java System Application Server Platform Edition 8.1 2005Q1
# J2SE 1.4.2
# J2EE 1.4 SDK Samples 2005Q1
# J2EE 1.4 API Documentation

I have also downloaded the tomcat 5.5.7 and the compat versions, set the java-home variable and got the tomcat welcome page successfully.

My path is set to:


My classpath is set to:


The first path is my working directory. The compilation error is package javax.servlet does not exist; package javax.servlet.http does not exist; It also points at all other places where the servlet classes are used.

Where am i going wrong? Do I need to download something else?


SCJP 1.2
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

With Tomcat, you don't need j2ee.
Don't know if it hurts but take it out for now.

Add TOMCAT_HOME/common/lib/servlet-api.jar to your classpath and try compiling.
Tomcat ships with the j2ee components it needs.

Let us know

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
Posts: 89
Thanks, it did compile after adding the classpath you mentioned.

The next question as you can guess is how to run the servlet on tomcat. I am used to javawebserver where we put the class files in servlets directory and htmls in public_html.

How does it work in tomcat? If it is complicated can somebody provide a link for a good read on how to run servlets on tomcat? Thanks again!
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

TOMCAT_HOME/webapps/YOUR_APP/jsps, html, etc..

It's covered here:

Also, I've published some simple war file examples that you can download and run. The directory structures and web.xml files in them are correct.
[ February 10, 2005: Message edited by: Ben Souther ]
M Streit

Joined: Jan 16, 2004
Posts: 27

You might find the following useful as well:

And there are probably no better books on the subject of servlets/jsp (tutorial type) than Kathy Sierra and Bert Bates' book:
and Marty Hall's book:

Also check out:

Hope you find these helpful...

M Streit

Joined: Jan 16, 2004
Posts: 27

Meant to include:

gaurav chhabra
Ranch Hand

Joined: Jul 24, 2004
Posts: 109
u can try the thing-----
compile like this way

javac -classpath c:\sun\appserver\lib\j2ee.jar;. name of the

may this will help u
I agree. Here's the link:
subject: How to compile servlets
Similar Threads
Issues Compiling With Javac
error compiling a servlet
'javax.servlet . * package does not exist !'
problem getting started
Problem compiling pgm