• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

Tomcat cannot find some of the lib jars in runtime.

Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Posts: 21004
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
Enterprise-grade Excel API for Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!