6

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?

Mikhail Batcer
  • 1,938
  • 7
  • 37
  • 57

1 Answers1

5

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

leet java
  • 304
  • 1
  • 3
  • 1
    I tried it and I on deploying I get: `Exception while loading the app : CDI deployment failure:Error instantiating class org.hibernate.validator.internal.cdi.ValidationExtension java.lang.RuntimeException: Error instantiating class org.hibernate.validator.internal.cdi.ValidationExtension `, then stacktrace: something with org.glassfish.grizzly, `Caused by: java.lang.AbstractMethodError at org.hibernate.validator.internal.cdi.ValidationExtension.(ValidationExtension.java:91)` – Mikhail Batcer Mar 16 '16 at 13:55
  • 1
    @MikhailBatcer did you solve your issue? I am fighting with the same thing. – AngelAvila Aug 23 '17 at 21:44
  • 1
    @AngelAvila If I remember correctly, I had to rename conflicting old libraries in Glassfish `modules` directory adding `.bak` in the end (or smth like that to backup them. Maybe moving to `bak` folder is better), and then put there libraries with versions I needed. New libraries should have exactly the same names as old ones. – Mikhail Batcer Aug 24 '17 at 07:26
  • @MikhailBatcer not really a solution, but a work-around I would say – Erdinc Ay Oct 02 '19 at 09:00
  • 1
    @ErdincAy I was too lazy and lacking time to post a bug report. Probably that would give a real solution. – Mikhail Batcer Oct 03 '19 at 08:30