3
votes

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.

4
Could you please provide the complete stack trace?Bhushan Bhangale
Yeah, NoSuchMethodError may suggest that the classes are being picked up but they conform to an old version of an interface (or just an old version of an implicit spec).Dan Gravell

4 Answers

5
votes

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.

1
votes

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.

0
votes

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

0
votes

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.