wood burning stoves*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to compile servlets" Watch "How to compile servlets" New topic
Author

How to compile servlets

Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
Posts: 89
Hi,

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:

c:\sue\projects\exercise\servlets;c:\J2EE1.4\bin;
c:\J2EE1.4\jdk\bin;c:\J2EE1.4\jdk\jre\bin;

My classpath is set to:

c:\sue\projects\exercise\servlets;c:\J2EE1.4\lib;
c:\J2EE1.4\jdk\lib;c:\J2EE1.4\jdk\jre\lib;

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?


Sue

SCJP 1.2
SCWCD 1.4
SCBCD 5.0
Ben Souther
Sheriff

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
Sheriff

Joined: Dec 11, 2004
Posts: 13410

TOMCAT_HOME/webapps/YOUR_APP
TOMCAT_HOME/webapps/YOUR_APP/jsps, html, etc..
TOMCAT_HOME/webapps/YOUR_APP/WEB-INF/web.xml
TOMCAT_HOME/webapps/YOUR_APP/WEB-INF/classes/YOUR_PACKAGE/YOUR_CLASSES
TOMCAT_HOME/webapps/YOUR_APP/WEB-INF/lib/JAR_FILES..

It's covered here:
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/appdev/index.html

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.
http://simple.souther.us
[ February 10, 2005: Message edited by: Ben Souther ]
M Streit
Greenhorn

Joined: Jan 16, 2004
Posts: 27
Sue,

You might find the following useful as well:

http://www.coreservlets.com/Apache-Tomcat-Tutorial/

And there are probably no better books on the subject of servlets/jsp (tutorial type) than Kathy Sierra and Bert Bates' book: http://www.amazon.com/exec/obidos/ASIN/0596005407/qid=1108089062/sr=2-1/ref=pd_ka_b_2_1/104-2470500-1671162
and Marty Hall's book:
http://www.coreservlets.com/#CWP2

Also check out:


Hope you find these helpful...

Mark
M Streit
Greenhorn

Joined: Jan 16, 2004
Posts: 27
Sue,

Meant to include: http://www.onjava.com/pub/a/onjava/2004/01/28/tomcat5.html

Mark
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 prog.java

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