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?
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.
Being persecuted doesn't in any way prove your righteousness or your beliefs. Many people get persecuted because they are repugnant or annoying. Or just because they can be.
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?