my dog learned polymorphism*
The moose likes Servlets and the fly likes compiling servlets under Tomcat 4.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "compiling servlets under Tomcat 4.0 " Watch "compiling servlets under Tomcat 4.0 " New topic
Author

compiling servlets under Tomcat 4.0

Sagar Bilgi
Ranch Hand

Joined: Apr 26, 2001
Posts: 37
Hi all,
I just downloaded Tomcat 4.0 on my windows NT machine and I have installed the same.I can get to the tomcat homepage localhost:8080 without any problems. My problem comes when I am trying to compile servlets under tomcat4.0. For some reason it is not including the servlet.jar files in the classpath.
I have set CATALINA_HOME and JAVA_HOME ( I previously had set TOMCAT_HOME FOR tomcat3.2.3..tried removing and adding and changing that and I doesnt work ). IN tomcat 3.2.3 u could go to the bin directory and say tomcat env and it would add the relevant classfiles to the classpath. IN 4.0 though a similar batch file exists called catalina, it does not seem to add all the relevant jars to the classpath and hence I am unable to compile under 4.0. When I cay catalina env in the bin directory I get the following statements
Using CATALINA_BASE: c:\tomcat
Using CATALINA_HOME: c:\tomcat
Using CLASSPATH: c:\tomcat\bin\bootstrap.jar;c:\jdk1.3.1\lib\tools.jar
Using JAVA_HOME: c:\jdk1.3.1
obviously its is not adding the servlet.jar and other relevant jars hence my problem. Am I missing something obvious here? I also tried manually adding the classpath of the servlet.jar to the classpath variable and even that didnt work.Can someone help me here?
Thanks
Sagar
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
I heartily recommend the ANT build environment for controlling these annoying classpath problems. ANT is sort of a super MAKE facility. You can download it from jakarta.apache.org
After an hour or so you will wonder how you ever got along without it.
Bill
Sagar Bilgi
Ranch Hand

Joined: Apr 26, 2001
Posts: 37
Hi Bill,
appreciate your recommendation but in my current setup can you recommend anything that I can do to get things working
Thanks
Sagar
p.s: ur books are great!
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

What are you using to compile the servlets?

If it's just a DOS window, then you can specify the classpath as a parameter.

java -cp .;c:\jars\servlet.jar MyServlet.java

If you're using an IDE, make sure that it uses the system CLASSPATH (For example, JBuilder doesn't).

Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

Hi Sagar, i copied my servlet.jar file to the c:\jdk1.4\lib folder in my win2000 machine and m compiling in jdk-bin folder. Also try so set the classpath in the command propmt each time u start the dos window....
Rather i m facing a problem in my house where Tomcat 4 is running excellently in win2000 but telling to set JAVA_HOME win98... ...but i did set everything in autoexec.bat file. Then i also set them in command prompt and checked that dos is using 4096kb memory. In dos propmt when i echo my java_home it shows my jdk installation folder but when i run tomcat it says to set JAVA_HOME. I m also using JSDK2.1 but in different port 6060....
Sagar, lemme know whether the trick worked and also plz any help to my problem....

------------------
Muhammad Ashikuzzaman (Fahim)
Sun Certified Programmer for the Java� 2 Platform
--When you learn something, learn it by heart!


Ashik Uzzaman
Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
Sagar Bilgi
Ranch Hand

Joined: Apr 26, 2001
Posts: 37
Hi Mike,
Thanks for ur advice.,I am using a DOS window for compilation and yeah I added the classpath in the javac command and it worked. Should I manually add each jar to the classpath? Also if I say classpath=c:\conf\lib\ will it pick up all the jars from the lib directory or should I say classpath=c:\conf\lib\*.jar
( I dont think the * would work )
Ashik, u might wanna try giving it the classpath of tools.jar and rt.jar when u compile ur programs..
Thanks
Sagar
Ray Smilgius
Ranch Hand

Joined: Jan 29, 2001
Posts: 120
you can put jar files that you need to use without setting the classpath statically or in a system variable just put it in the ext folder

C:\jdk1.3.1_01\jre\lib\ext
then in your code, you just use import myjar.*;

It works like a charm hope it helps.
Ray Smilgius
------------------
Sun Certified Java Programmer
Sun Certified Java Developer
I-Net Certified
A+ Certified
Network+ Certified
MCP


SCJO, SCJD, SCWCD, I-Net+, A+, Network+, MCSD, MCDBA, MCP, MCT
Vanitha Sugumaran
Ranch Hand

Joined: Apr 11, 2001
Posts: 356
Hi,
I have added this line when I couldn't compile the servlets.
SET CLASSPATH=C:\PROGRAM FILES\APACHE TOMCAT 4.0\COMMON\LIB\SERVLET.JAR

You can also copy the servlets.jar and put it in jre\lib\ext.
Hope this helps,
Vanitha.
[This message has been edited by Vanitha Sugumaran (edited November 14, 2001).]
Donald Nunn
Ranch Hand

Joined: Nov 11, 2000
Posts: 200
Hello, All. I having the same problems.
SET CLASSPATH=C:\PROGRAM FILES\APACHE TOMCAT 4.0\COMMON\LIB\SERVLET.JAR
I set my class path just like this and it's not seeing the jar file when I attempt to compile my servlet program. I can set the class path as mentioned in several of the other responses and it compiles, however, that's the only way I've gotten it to work.
Another thing is I'm not that clear on how class paths work and how they should be set up in the autoexec.bat file. Would anyone know of a resource that can explain it throughly? Also, how do you set up JAVA_HOME and TOMCAT_HOME. I guess what I'm looking for is the correct syntax and where.
thanks,


------------------
Donald Nunn
Sun Certified Programmer for the Java� 2 Platform


<b>Donald Nunn</b><br />Sun Certified Programmer for the Java 2 Platform
Sagar Bilgi
Ranch Hand

Joined: Apr 26, 2001
Posts: 37
Hi all,
Thanks for everyones reply to this post. I tried copying the jar files to the ext directory and it works like a charm.
I dont know what you mean when u say u dont understand how to set JAVA_HOME and TOMCAT_HOME..
all u need to do is add the follwing lines in your autoexec.bat file.
set JAVA_HOME=c:\jdk1.3.1 (wherever ur jdk resides)
set TOMCAT_HOME=c:\jakarta-tomcat-3.2.3 ( wherever ur tomcat is installed)
the reason we need to set it is so that the batch files which are provided with tomcat can run properly as they rely on these values to set up everything correctly. Also as I mentioned earlier if u have tomcat3.2.3 all u need to do is open a dos window go to the bin directory and say tomcat env. It will add all the relevant jars to the classpath.
donald, u might want to lok at these links to get an idea of how classpaths work. http://java.sun.com/products/jdk/1.2/docs/tooldocs/win32/classpath.html
http://www.weblogic.com/docs51/admindocs/classpath.html#whatis

HTH
Sagar
Donald Nunn
Ranch Hand

Joined: Nov 11, 2000
Posts: 200
Thanks, Sagar. You answered all of my questions. I just needed to see the syntax for JAVA_HOME and TOMCAT_HOME.
Thanks, a lot.
------------------
Donald Nunn
Sun Certified Programmer for the Java� 2 Platform
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16103
    
  21

Don't overlook what William said about Ant, though. It's a lot better than batch or makefiles. Ant build files are simple, handle dependent build steps, and are OS-independent. Windows environment variables (such as CLASSPATH, JAVA_HOME, and the tomcat variables) aren't even handled consistently between the DOS-based Windows (9x) and the NT-based Windows environments (NT, Win2K, and - I presume - XP).


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compiling servlets under Tomcat 4.0