tags:

views:

719

answers:

3

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.

+5  A: 

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.

kgiannakakis
Thanks, the problem was that another jar file (with different name) existed in Lib folder, and tomcat picked it up first, due to sorting the files with filename. Removing the old jar files fixed the error, to no surprise :)
Hadi Eskandari
+1  A: 

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.

Thilo
A: 

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

Yonatan Maman