Tomcat deployment problem using jar file instead of classes
Question
We're deploying a WAR file into Tomcat 5.5 and it works fine if WEB-INF\classes contains .classes files, but if we move the .jar file containing that .classes into WEB-INF\lib, we get an exception on runtime complaining that java.lang.NoSuchMethodError, but existing class file in .jar file contains the class and method does exits!
Any help on this would be appreciated.
Solution
This could be caused due to a class conflict. Make sure that there isn't an older version of the Class somewhere (Tomcat's shared folder, WEB-INF/classes, WEB-INF/lib). If this is the case, you practically can't know which class Tomcat will load. If it picks one without the method, the exception you are experiencing will occur.
OTHER TIPS
Since you are getting a NoSuchMethodError, and not a ClassNotFoundError, it means that you have an old version of the class somewhere (outside of the jar file). You need to find and remove it.
This is defently class closin please take a look in here http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html#Class%20Loader%20Definitions
as you can see there is a higher priority for classes under WEB-INF/classes comparing WEB-INF/lib . You have the two classes with the same name (and package). When one of them is in the classes folder that it has higher priority. when they are both in lib folder then the second one get first (jars have a priority based on their alpha-betical order )
This can explain your situation.
Hope it helps -- Yonatan
From the perspective of a web application, class or resource loading looks in the following repositories, in this order:
Bootstrap classes of your JVM
System class loader classes (described above)
/WEB-INF/classes of your web application
/WEB-INF/lib/*.jar of your web application
Common class loader classes (described above)
The locations searched by "Common class loader" are defined by the common.loader property in $CATALINA_BASE/conf/catalina.properties. This is where we enable/define share location;
shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar
And the above order gives more insight in to the issue you faced.