9

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...)

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
sly7_7
  • 11,961
  • 3
  • 40
  • 54
  • Did you ever find a workaround? – JagWire Feb 19 '14 at 21:55
  • 1
    Unfortunately, not at all... – sly7_7 Feb 20 '14 at 08:00
  • 1
    In case you care, I found an embedded v4 build and the classpath issue went away. You can find the build here: http://grepcode.com/snapshot/maven.java.net/content/groups/promoted/org.glassfish.main.extras/glassfish-embedded-all/4.0.1-b01 – JagWire Feb 20 '14 at 21:21
  • 1
    @JagWire I'm not working with Glassfish anymore, but it's a very good thing to know they have fix this. I will update Kevin's anwser with your link. Thanks a lot for that :) – sly7_7 Feb 21 '14 at 14:34
  • I have a similar problem, not with glassfish, but with some other jar library from my poms. Unfortunately I have a lot of libraries in my poms. Can someone tell me how to track down which jar is causing a conflict? I have no idea how to do it. All I know is my code crashes when I try to edit my guava in my poms to higher than 19.0 - and I want to use functionality from 21 in my project! but can't as long as this problem persists... – ycomp Jun 01 '17 at 05:36

3 Answers3

7

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

Community
  • 1
  • 1
Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
  • We try it, but it does not work in our case... This results in ClassCastException (probably due to same classes loaded by different classloaders) – sly7_7 Oct 03 '11 at 08:22
4

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.

sly7_7
  • 11,961
  • 3
  • 40
  • 54
Kevin Bourrillion
  • 40,336
  • 12
  • 74
  • 87
0

I was able to make the error go away by using the following Glassfish v4 build:

http://grepcode.com/snapshot/maven.java.net/content/groups/promoted/org.glassfish.main.extras/glassfish-embedded-all/4.0.1-b01

Might be worth taking a look.

JagWire
  • 269
  • 2
  • 16