Two Laptop Bag*
The moose likes Tomcat and the fly likes can't find classes in my webapps lib directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "can Watch "can New topic
Author

can't find classes in my webapps lib directory

Michael Beck
Greenhorn

Joined: Mar 11, 2005
Posts: 19
I've searched the forums and seen this question asked, but there doesn't seem to be an answer to it. I deployed a webapp of mine to tomcat 5.5 as a .war file. The deployment works and I can call jsps. I try to call a servlet which uses a .jar file which is in my application's /WEB-INF/lib/ directory.
I get a NoClassDefFoundError for a class that the servlet tries to call. However, if I add my .jar file to $tomcat-home/common/lib everything works fine. I can't imagine I would need to add all my .jar files to the common/lib to get them to work. Please let me know what I need to do to have the files in my own application's \WEB-INF\lib directory to be seen.

Thanks in advance.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You should never need to add them to common/lib.
Are the classes in a package?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Michael Beck
Greenhorn

Joined: Mar 11, 2005
Posts: 19
there are multiple .jars including castor-jdo jars, commons classes, mysql connector, xml parsers etc...so yes, they are in packages within the .jars
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Is it a JDBC driver class that can't be found?
If you're setting up container managed connection pooling, then yes, the driver libraries have to be in a place where the container can access them.
Michael Beck
Greenhorn

Joined: Mar 11, 2005
Posts: 19
yes, it is a jdbc class that cant be found. i'm using castor-jdo to connect to a mysql database so this wouldn't be container managed (unless i'm confused about what container managed is)
Michael Beck
Greenhorn

Joined: Mar 11, 2005
Posts: 19
Do I need to do anything with any of the files in the /conf directory to define my web app context? I wonder if thats why those files aren't in the classpath.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you're planning on using container managed connection pooling, you'll want to see this page:
http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html

There are several ways to deploy an app in Tomcat.
See:
http://tomcat.apache.org/tomcat-5.5-doc/deployer-howto.html
Michael Beck
Greenhorn

Joined: Mar 11, 2005
Posts: 19
I think I figured out why it can't find the class. I am using castor-jdo to do object/database mapping with a mysql database. Castor-jdo uses a class javax.transaction.Synchronization...it doesn't seem to work without this. This class is in j2ee.jar
When I start my webapp I see
INFO: validateJarFile(C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ahs96\WEB-INF\lib\j2ee.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

So j2ee.jar never gets loaded when it is in my webapp. It only gets loaded if I put it in the $CATALINA_HOME/common/lib directory.

The problem is I need this class for the castor stuff to work. It 'does' work putting it in $CATALINA_HOME/common/lib directory. but this is not the right way to do it. Can anyone give me some insight into this?

Thanks
Michael Beck
Greenhorn

Joined: Mar 11, 2005
Posts: 19
I've discovered that j2ee.jar is unnecessary. jta1.0.1.jar
includes the required interfaces. the jar is in
the lib directory of the full castor download.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: can't find classes in my webapps lib directory