aspose file tools*
The moose likes Tomcat and the fly likes Tomcat cannot find some of the lib jars in runtime. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat cannot find some of the lib jars in runtime." Watch "Tomcat cannot find some of the lib jars in runtime." New topic
Author

Tomcat cannot find some of the lib jars in runtime.

Dmitry Zhuravlev
Ranch Hand

Joined: Apr 14, 2010
Posts: 91
My application is deployed on Tomcat. It uses several apache frameworks, such as commons, logging and some others. I observe the following situation:

1) on my own machine everything works ok.

2) when I deploy my application on my hosting's Tomcat it cannot find LogFactory class from apache.commons.logging and some other apache classes from other commons libraries (StringUtils for example), and also some google libraries. NoClassDefFoundError is thrown.

I asked hosting support for help and they said that if I use some jars in Tomcat Listeners I should place that jars in Tomcat classpath, not in standart application classpth. I.e. I should place them in some lib folder inside Tomcat's root. Is this correct?
Indeed, they placed the commons-logging jar into the tomcat's own lib folder and the problem disappeared. But I cannot really place all my libs into the Tomcat's own libs, its stupid.

Strange thing is that before I replaced some library with its new version everything worked ok. Is there some cache or something to be cleaned or refreshed when I change the libraries of my webapp?

Note: probably I have several apache commons libraries on my classpath. It worked ok before, but now I have this problem. Can several similair or different versioned jars be the reason of this error?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15665
    
  15

It is usually very unsafe to put application jars in the Tomcat library. They should be placed in the application's WEB-INF/lib directory. The jars you mentioned DEFINITELY should not be placed in the Tomcat lib directory.

You can get a NoClassDefFoundError exception if you have application jars in the Tomcat library because they may attempt to call out to classes that exist in both places and get the wrong one. You might also be suffering from Java's equivalent to "DLL Hell".

One thing that may also be a factor is that when you redeploy a WAR and an older exploded copy of the WAR already exists in the TOMCAT_HOME/webapps directory, the older copy will continue to be used. So it's a good idea to delete older deployments before adding new ones. Note that if you delete a WAR while Tomcat is active, Tomcat may delete its corresponding TOMCAT_HOME/conf/Catalina/localhost/xxxx.xml file if one is present, so only delete WARs while Tomcat is not running.


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: Tomcat cannot find some of the lib jars in runtime.
 
Similar Threads
How do I deal with Glassfish included libs crashing with application supplied libs?
rich:tree working now... all the work has finally paid off - THANKS
Tomcat 5.5 Class loading issues--and I have done some home work on this one
Trying to add string values to a list or some type of collection through iterator
tomcat6 class not found: ServletContextListener