Skip to content
Advertisement

Gradle, Apache TomEE – TomEEWebappClassLoader loader constraint violation

The gradle project runtime at Apache TomEE plus has the error

java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/tomee/catalina/TomEEWebappClassLoader) previously initiated loading for a different type with name “javax/faces/context/ExternalContext” at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:756) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2489) at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:875) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1376) at org.apache.tomee.catalina.TomEEWebappClassLoader.loadClass(TomEEWebappClassLoader.java:184) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1220) at org.apache.tomee.myfaces.TomEEWebConfigProvider.getFacesServletMappings(TomEEWebConfigProvider.java:36) at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:163) at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:103) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4766) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.startup.Catalina.start(Catalina.java:772) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)

The gradle.properties

dependencies {
    compile files('lib/javaee-api-7.0.jar')
    compile fileTree(dir: 'WebContent/WEB-INF/lib', include: '**/*.jar')
    
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile group: 'org.jglue.cdi-unit', name: 'cdi-unit', version: '3.1.4'
    testCompile group: 'org.mockito' ,name: 'mockito-all', version:'1.10.19'
    compile group: 'org.apache.shiro', name: 'shiro-all', version: '1.3.2'
    compile group: 'jaxen', name: 'jaxen', version: '1.1.6'
    compile 'org.apache.velocity:velocity:1.7'
}

The jar files in WEB-INF/lib enter image description here

Advertisement

Answer

This error might happen when your module provide classes that are already provided by javax.faces.context.ExternalContext. A simple way to fix this error is declaring the related library as a dependency in your custom module and setting a provided scope in gradle by the runtimeOnly configuration.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement