users@glassfish.java.net

[gf-users] How can I prevent application class conflict with bundled Guava (4.1)

From: Pawel Veselov <pawel.veselov_at_gmail.com>
Date: Thu, 19 Feb 2015 13:01:05 -0800

Hi.

Running on GlassFish Server Open Source Edition 4.1 (build 13).

I have an application that uses, and packages, Google collect library.
GF 4.1 also uses classes of the same library, as part of Guava.
Specifically, there is a ImmutableSet class that have differences in
signatures for certain methods.

(GF) ./glassfish/modules/guava.jar
: com/google/common/collect/ImmutableSet.class
(MY) lib/google-collect-1.0-rc1.jar
: com/google/common/collect/ImmutableSet.class

Once GF attempts to load the web application
(com.sun.enterprise.web.WebModule.start(WebModule.java:691)), a signature
mismatch exception is thrown, since the class is (apparently) being loaded
from the "Common" classloader.

The application is deployed as EAR. The EAR contains the web module, but
all the library jar files are in the 'lib' directory of the EAR itself, WAR
file has practically no libraries. This is because there are multiple
sub-applications in the EAR, and they all should share the libraries.

How do I make the "Applib" classloader load the class instead? I did
declare '<class-loader delegate="false"/>' in glassfish-web.xml, but that
doesn't help, probably because the JARs are not in the web app, but are in
the enterprise app instead. I don't see any class-loader related
declarations that I can specify in glassfish-application.xml.

The stack trace:
  ContainerBase.addChild: start:
org.apache.catalina.LifecycleException:
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'verificationReportExport' defined in ServletContext
resource [/WEB-INF/client-controller.xml]: Instantiation of bean failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Could not instantiate bean class
[com.xxx.xxx.portal.reports.controller.VerificationReportExportController]:
Constructor threw exception; nested exception is
java.lang.NoSuchMethodError:
com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
        at
org.apache.catalina.core.StandardContext.start(StandardContext.java:5954)
        at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
        at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
        at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
        at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
        at
com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2286)
        at
com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1932)
        at
com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
        at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
        at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)
        at
org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352)
        at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:500)
        at
com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:406)
        at
com.sun.enterprise.v3.server.ApplicationLoaderService.postConstruct(ApplicationLoaderService.java:243)
        at
org.jvnet.hk2.internal.ClazzCreator.postConstructMe(ClazzCreator.java:329)
        at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:377)
        at
org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:461)
        at
org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext.findOrCreate(AsyncRunLevelContext.java:227)
        at
org.glassfish.hk2.runlevel.RunLevelContext.findOrCreate(RunLevelContext.java:84)
        at
org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2258)
        at
org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:105)
        at
org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:87)
        at
org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.oneJob(CurrentTaskFuture.java:1162)
        at
org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.run(CurrentTaskFuture.java:1147)
        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'verificationReportExport' defined in
ServletContext resource [/WEB-INF/client-controller.xml]: Instantiation of
bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not instantiate
bean class
[com.xxx.xxx.portal.reports.controller.VerificationReportExportController]:
Constructor threw exception; nested exception is
java.lang.NoSuchMethodError :
com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:955)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:901)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
        at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
        at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:574)
        at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
        at
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
        at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
        at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
        at
org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:5394)
        at
com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:743)
        at
org.apache.catalina.core.StandardContext.start(StandardContext.java:5932)
        ... 26 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not
instantiate bean class
[com.xxx.xxx.portal.reports.controller.VerificationReportExportController]:
Constructor threw exception; nested exception is
java.lang.NoSuchMethodError:
com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
        at
org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
        at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:71)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:948)
        ... 42 more
Caused by: java.lang.NoSuchMethodError:
com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
        at
com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399)
        at
com.google.gdata.wireformats.AltFormat$Builder.setAcceptableXmlTypes(AltFormat.java:387)
        at
com.google.gdata.wireformats.AltFormat.<clinit>(AltFormat.java:49)
        at com.google.gdata.client.Service.<clinit>(Service.java:558)
        at
com.xxx.xxx.portal.reports.controller.VerificationReportExportController.<init>(VerificationReportExportController.java:95)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
        at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
        at
org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
        ... 44 more