users@glassfish.java.net

EJBs with Guava Libraries conflict with Embedded Glassfish

From: <forums_at_java.net>
Date: Tue, 3 Apr 2012 17:30:35 -0500 (CDT)

I have created a very simple maven experiment containing one Singleton bean.
The project consists of a parent pom, an ear, and an ejb jar that depends on
guava 11.0.2. When I execute this with the goal /integration-test/, I get the
error java.lang.NoSuchMethodError:
com.google.common.collect.ImmutableSet.copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableSet;
I have seen the solution involving *<class-loader delegate="false" />* at
stackoverflow.com [1], but I'm not sure if this even applies to a non-WAR
project. I understand this may be because embedded glassfish has a
conflicting version of guava. How can I make this experiment work? The EJB
class: package com.acme.guavaEJB; import static
com.google.common.collect.Lists.newArrayList; import java.util.List; import
java.util.Set; import javax.annotation.PostConstruct; import
javax.ejb.Singleton; import javax.ejb.Startup; import
com.google.common.collect.ImmutableSet; @Singleton @Startup public class
GuavaService { @PostConstruct public void test() { List colors =
newArrayList("red", "green", "blue"); Set colorSet =
ImmutableSet.copyOf(colors); System.out.println(colorSet.size()); } } Parent
pom: <?xml version="1.0" encoding="UTF-8"?> <project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.acme</groupId>
<artifactId>malachite</artifactId> <version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging> <name>malachite</name> <modules>
<module>guavaEAR</module> <module>guavaEJB</module> </modules> </project> EAR
pom: <?xml version="1.0" encoding="UTF-8"?> <project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <parent>
<artifactId>malachite</artifactId> <groupId>com.acme</groupId>
<version>0.0.1-SNAPSHOT</version> </parent> <artifactId>guavaEAR</artifactId>
<packaging>ear</packaging> <name>guavaEAR</name> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <build> <plugins> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version>
<configuration> <source>1.6</source> <target>1.6</target> </configuration>
</plugin> <plugin> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId> <version>2.6</version>
<configuration> <version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir> <modules> <ejbModule>
<groupId>com.acme</groupId> <artifactId>guavaEJB</artifactId> </ejbModule>
</modules> </configuration> </plugin> <plugin>
<groupId>org.glassfish.embedded</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>3.1.2</version> <configuration>
<goalPrefix>embedded-glassfish</goalPrefix>
<app>${project.build.directory}/${project.build.finalName}.ear</app>
<port>8888</port> <ports> <https-listener>8989</https-listener> </ports>
<name>${project.build.finalName}</name>
<serverID>guavaEAR-embedded</serverID>
<glassfishProperties></glassfishProperties> </configuration> <executions>
<execution> <id>run</id> <goals> <goal>run</goal> </goals> </execution>
</executions> </plugin> </plugins> </build> <dependencies> <dependency>
<groupId>com.acme</groupId> <artifactId>guavaEJB</artifactId>
<version>0.0.1-SNAPSHOT</version> <type>ejb</type> </dependency>
</dependencies> </project> EJB pom <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <parent>
<artifactId>malachite</artifactId> <groupId>com.acme</groupId>
<version>0.0.1-SNAPSHOT</version> </parent> <artifactId>guavaEJB</artifactId>
<packaging>ejb</packaging> <name>guavaEJB</name> <properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies> <dependency> <groupId>javax</groupId>
<artifactId>javaee-api</artifactId> <version>6.0</version>
<scope>provided</scope> </dependency> <dependency>
<groupId>com.google.guava</groupId> <artifactId>guava</artifactId>
<version>11.0.2</version> </dependency> </dependencies> <build> <plugins>
<plugin> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version>
<configuration> <source>1.6</source> <target>1.6</target> <compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs> </compilerArguments>
</configuration> </plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId> <version>2.3</version>
<configuration> <ejbVersion>3.1</ejbVersion> </configuration> </plugin>
</plugins> </build> </project>

[1]
http://stackoverflow.com/questions/7613059/how-to-deal-with-classpath-conflict/7613250#7613250

--
[Message sent by forum member 'biggus']
View Post: http://forums.java.net/node/884793