Prevent Glassfish from using its own versions of l

2019-05-10 11:12发布

问题:

Glassfish has whole bunch of third-side libraries stored in its modules directory. To my surprise, if my project uses a library which is present there, Glassfish will provide it from there, instead of the right version I have packed-in in my WAR file.

This leads to a number of errors. For example, I use jackson-datatype-joda version 2.6.3, which requires jackson-databind with same version, and it is included in my project. But Glassfish replaces that package with version 2.3.2, which leads to this issue.

How can I prevent Glassfish (4.1) from replacing the libraries I use with another versions?

回答1:

Add a glassfish-web.xml file to your WEB-INF directory containing something like,

<glassfish-web-app>
  <class-loader delegate="false" />
</glassfish-web-app>

This will ensure classes are loaded from your war before the server classpath