ClassLoader + tomcat

R

read-the-signature

Greetings,

I don't know if this is the right group to pose this question to or not.
If there is a better group, let me know.

I'm developing a web application run under tomcat and am using jar files.
For some reason. I'm let to believe that by default tomcat makes available
through its class loader all java classes in jar files at
$CATALINA_HOME/webapps/app/WEB-INF/lib.
 
R

read-the-signature

Greetings,

Excuse the follow up to my own post but my newsreader program went beserk
and posted prematurely.

I don't know if this is the right group to pose this question to or not.
If there is a better group, let me know.

I'm developing a web application run under tomcat and am using jar files.
I'm let to believe that by default tomcat makes available through its class
loader all java classes in jar files at
$CATALINA_HOME/webapps/app/WEB-INF/classes/lib.
I'm finding that this is not the case on the tomcat instance that I'm using
as I've jar'd up a mysql driver, DbConnectionBroker, and various utiliity
classes that I've written and place this jar file at the above location.
After several restarts of tomcat, the application is not finding these
classes in the jar file.

I thought tomcat automatically made available jar files to the application
installed in this directory. Is there some configuration that I must perform
in tomcat to make these jar files visible
 
W

Wendy S

I'm developing a web application run under tomcat and am using jar files.
I'm let to believe that by default tomcat makes available through its
class loader all java classes in jar files at
$CATALINA_HOME/webapps/app/WEB-INF/classes/lib.
I'm finding that this is not the case on the tomcat instance that I'm
using as I've jar'd up a mysql driver, DbConnectionBroker, and various
utiliity classes that I've written and place this jar file at the above
location. After several restarts of tomcat, the application is not finding
these classes in the jar file.

What version of Tomcat, what version of the JDK (and whose) are you using?
List the contents of the .jar file, are the classes properly arranged in
directories matching their package structure? (They _are_ packaged,
right?) What exact error message are you seeing?

Can you write a simple Java class with a main method that does basically the
same thing you're trying to do from a Servlet? (IOW, have your classes
already been tested thoroughly before you add Tomcat to the mix?)

Check the common directories and make sure there's nothing in there that
conflicts with the classes you're trying to load. (Did you maybe drop a
mysql driver in common/lib previously?)
 
R

read-the-signature

Wendy S said:
What version of Tomcat, what version of the JDK (and whose) are you using?
List the contents of the .jar file, are the classes properly arranged in
directories matching their package structure? (They _are_ packaged,
right?) What exact error message are you seeing?

Can you write a simple Java class with a main method that does basically the
same thing you're trying to do from a Servlet? (IOW, have your classes
already been tested thoroughly before you add Tomcat to the mix?)

Check the common directories and make sure there's nothing in there that
conflicts with the classes you're trying to load. (Did you maybe drop a
mysql driver in common/lib previously?)

I'm using tomcat 4.1.24 and Sun's jdk version 1.3.1-p8 built for a FreeBSD
4.8 system. The classes are listed and arranged properly. I moved the
mysql driver and DbConnectionBroker class to common/lib/mysql.jar and the
application finds these two classes but, I am using util.MySqlConnection a
class that I wrote and is jar'd up at
$CATALINA_HOME/webapps/myapp/WEB-INF/classes/lib/util.jar

$ jar tvf util.jar

0 Sun Jul 13 11:50:52 CDT 2003 META-INF/
71 Sun Jul 13 11:50:52 CDT 2003 META-INF/MANIFEST.MF
0 Sun Jul 13 11:50:40 CDT 2003 util/
1161 Sun Jul 13 11:43:18 CDT 2003 util/MySqlConnection.class

If I move util.jar to common/lib and restart tomcat, the application
works fine. But when I put the util.jar where I want it with the application
at myapp/WEB-INF/classes/lib/util.jar, I run into the problem.

The docmentation I'm reading says that the class loader should load the util.jar
from this location but its not. Do you know what I should check with the
tomcat configuration?

thanks
 
N

Nigel Wade

I found the problem. The jar should be at
$CATALINA_HOME/webapps/myapp/WEB-INF/lib.

Correct. Jars go in WEB-INF/lib and classes in WEB-INF/classes.

That's for servlet specific code. If you want the jars/classes to be
available to all servlets then you can put them in
$CATALINA_HOME/common/{lib,classes}.
 
N

Nigel Wade

Nigel said:
Correct. Jars go in WEB-INF/lib and classes in WEB-INF/classes.

That's for servlet specific code. If you want the jars/classes to be
available to all servlets then you can put them in
$CATALINA_HOME/common/{lib,classes}.

Woops, that should read $CATALINA_HOME/shared/{lib,classes}.

They can go in common, but that's supposed to be for classes which are
needed by both Tomcat itself and serlvets.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top