• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat not loading its jars to classpath at run time

 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,
I'm using Tomcat 5.5.27 version & this is my configuration of environment variables.


I've read that


Tomcat automatically appends the location of its jar files to your existing CLASSPATH.



Then I created a simple webapplication with the following directory structure:

My java source is in src/WebTest.java



when I compile it :


1)It clearly meant that Tomcat has not loaded its jar servlet-api.jar into the classpath & why is it happening & what can be done to rectify this

2) Since I've ant I want to use Ant to separate source from the generated class files.
How to use that.
If i have the package structure com.common.java;
then the class files should be in webinf/classes/com/common/java/WebTest.class
How this can be achieved using Ant.
Remember ant is in my path.

BestRegards
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where you placed your servlet-api.jar . better to place in tomcat/common/lib
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The server was started using startup.bat
This is the document trace which i got when I run the server
I ran the server by

Server trace:

Now when i compile, by appending the jar manually to the classpath it's working.

1)Why we should manually append the jar to the classpath doesn't Tomcat does it of its own

2) How to use Ant here to separate java from class files.
Regards.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear seetharaman venkatasamy,
My servlet-api.jar is only in CATALINA_HOME\common\lib.
Where CATALINA_HOME is pointing to E:\apache-tomcat-5.5.27
Regards.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1)It clearly meant that Tomcat has not loaded its jar servlet-api.jar into the classpath & why is it happening



Because here you are compiling the source files which has nothing to do with the tomcat (It's JAVA compiler you are using ). By the way it's really a bad practice to put the source files & compiling from inside the Application server.

Keep your development environment out of application server. When you want to deploy you may create a WAR or move the necessary files to the application server.

If i have the package structure com.common.java;
then the class files should be in webinf/classes/com/common/java/WebTest.class
How this can be achieved using Ant.



You have to use Ant's javac Task with srcdir and destdir attributes. Have a look at the manual for complete information.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After the class gets compiled , i enhanced the web.xml .
This is my web.xml

My class file is in classes folder.
1)Then I created a war file using

2) Copied these war file in webapps folder

3) Then I shutdown the server & restarted the server.

4) When I try to run


It says an error


HTTP Status 404 - /FirstApplication/

--------------------------------------------------------------------------------

type Status report

message /FirstApplication/

description The requested resource (/FirstApplication/) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.27



How this can be fixed.
Is my web.xml proper.
I'm using tomcat version 5.5.27
Regards.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about http://localhost:8080/FirstApplication/start-web-test since that's the only resource you have mapped?

Does the Tomcat Manager (usually at http://localhost:8080/manager/html/list) list the application as running?
[ December 23, 2008: Message edited by: Ulf Dittmer ]
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


What about http://localhost:8080/FirstApplication/start-web-test since that's the only resource you have mapped?


Correct ! Now when I go over the above link it's working & I get the output


A Simple Web Application
Here's some text...
...and a bit more text



But,


Does the Tomcat Manager (usually at http://localhost:8080/manager/html/list) list the application as running?


No.
The error it's showing is:


HTTP Status 403 - Access to the requested resource has been denied

--------------------------------------------------------------------------------

type Status report

message Access to the requested resource has been denied

description Access to the specified resource (Access to the requested resource has been denied) has been forbidden.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.27



Thanks Ulf Dittmer for your valuable input.

For vijitha,


By the way it's really a bad practice to put the source files & compiling from inside the Application server.


I'm very eager to know why is it so? Because inside the application, i'm separating the source & class files right.


Because here you are compiling the source files which has nothing to do with the tomcat (It's JAVA compiler you are using )


But i'm using some dependencies ( some classes of servlet-api.jar) in my source file(WebTest.java) which directly access the tomcat dependencies only right.

You have to use Ant's javac Task with srcdir and destdir attributes. Have a look at the manual for complete information.


Certainly & thanks for the links.
Regards.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't Tomcat load all of its jars inside common\lib to classpath when we start the server .
I have JAVA_HOME & also CATALINA_HOME defined properly, which is echoed when the server is started up.(Please see my second post)
Regards.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Doesn't Tomcat load all of its jars inside common\lib to classpath when we start the server.


Yes it does, but as was said above, Tomcat has nothing to do with the Java compiler. And compiling servlets has no dependency on Tomcat - rather it depends on the jar file that contains the Servlet API. Tomcat just happens to include this jar file, that's all.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Understood !
When we are compiling, we are compiling with the java compiler javac, which as of such doesn't know about servlet-api.jar or any other jars, which has to be directed using javac -classpath.
Then what is the use of Tomcat loading all the jars at the time of starting the server?
Regards.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How could Tomcat function if it didn't have the servlet API and all those other jar files?
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For what function does Tomcat is loading these jars like servlet-api.jar & other jars in the classpath.
Regards.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any replies?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once again:

Originally posted by Ulf Dittmer:
How could Tomcat function if it didn't have the servlet API and all those other jar files available?



If you're curious what's inside of these jars, you can use "java -tf foobar.jar" to see all the classes. And if you're really curious how it all works, well, it's open source, so the source code is available for study.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic