This topic will help us understand a little more about the class loading of applications using packaging, in the case of WAR and EAR files.
Every WAR file is considered to be a single module, so all the libs that are in WEB-INF/lib
and WEB-INF/classes
will be treated the same way. Thus, all classes packaged along with the application will be loaded in the same class loader. For a WAR application, when using Maven, it is very practical to resolve all dependencies; for example, if your application uses the Servlet API, just add the following code on to your project POM
:
<dependencies> ... <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency> … </dependencies>
However, if you wish to use the Servlet API provided by the container or by the EAR/lib
JARs, you must configure the scope of the dependency...