M Sach
M Sach

Reputation: 34424

Configuration to get class picked from classes folder instead of lib folder in Tomcat?

I have same class file under classes folder and also in jar file inside lib folder.But the class is getting picked up from jar file. As per my understanding when this is the case , class under classes folder gets preference over jar file. At least this is the behaviour i have seen in glassfish. But this is not the behaviour in tomcat. Do i need to do any configuration in case of tomcat to give the preference to classes under classes folder? I am using tomcat 6.0.26.

Upvotes: 2

Views: 1120

Answers (1)

JB Nizet
JB Nizet

Reputation: 692231

The spec (2.4) says:

The Web application class loader must load classes from the WEB-INF/classes directory first, and then from library JARs in the WEB-INF/lib directory.

So if Tomcat loads from the jar first, it's not compliant with the spec.

Its documentation says:

Therefore, 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)

So I'm surprised you're seeing such a behavior. If you're absolutely sure that the class is not in some jar in Tomcat's own classpath, file a bug report. Before doing that, also make sure to clear Tomcat's work directory, or even to start from a fresh install of Tomcat.

The workaround is of course to repackage the jar file to include your modified class instead of relying on the classloading order.

Upvotes: 3

Related Questions