How to deal with classpath conflict
-
05-02-2021 - |
Pergunta
In my project, I'm using both glassfish-embedded 3.1.1 and the guava lib... The problem is that glassfish comes with the old implementation of guava (ie google-collections)...
This results in NoSuchMethodError at runtime, for example when using Lists.reverse(), or Sets.newIdentityHashSet() which were introduced later in guava.
I don't find any solution to solve this... (the only one is to manually trash the com/google classes directory in the glassfish jar...)
Solução
Glassfish should never have included com.google classes in their own jar. That was an error.
UPDATE[@sly7_7]: It seems like glassfish does not include guava in their own jar anymore, but it depends on the guava artifact instead. This should resolve the problem. Thanks to @JagWire for pointing this.
Outras dicas
You can overcome this be specifying the below. Read the Delegation section of the Class Loaders chapter.
<class-loader delegate="false" />
Check this SO post for class loading in Java EE apps in general: Java EE class loading standard
I was able to make the error go away by using the following Glassfish v4 build:
Might be worth taking a look.