Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat 8 classloading - difference between JAR in [WEB-INF/lib] and [tomcat/lib]

It says here that the common classloader is visible to all web application. So what is the difference between having a JAR file within the WEB-INF/lib folder of my war application and having the same JAR file within Tomcat's lib folder?

This JAR is a provider for a Java SPI that I created. When I have it under WEB-INF/lib, everything works perfectly. But if I try to put this JAR under Tomcat's lib folder (or under shared/lib after configuring it in catalina.properties) I get errors. The second option is better for me because I need total decoupling of my application and the provider.

The error I get is a ClassNotFoundException for the interface that represents my service (which the JAR implements). This interface is in a third project, which is a dependency for my war application.

like image 496
Fred Porciúncula Avatar asked Mar 15 '23 13:03

Fred Porciúncula


1 Answers

The tomcat/lib directory should be used for shared libraries for the whole web server and WEB-INF/lib only for one web application.

like image 171
Crazyjavahacking Avatar answered Apr 07 '23 10:04

Crazyjavahacking