Apache TomEE plus上的gradle项目运行时有错误
java.lang.LinkageError: loader constraint viruation: loader (org/apache/tomee/catalina/TomEEWebappClassLoader 的实例) 之前在java.lang.ClassLoader.defineClass1(Native Method)上启动了名为“javax/faces/context/ExternalContext”的不同类型的加载,网址为java.lang.ClassLoader.defineClass(ClassLoader.java:756) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)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) atorg.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) atorg.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)
梯度属性
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'
}
WEB-INF/lib 中的 jar 文件在此处输入图像描述
当您的模块提供的类已经由javax.faces.context.提供时,可能会发生此错误。修复此错误的简单方法是在自定义模块中将相关库声明为依赖项,并通过runtimeOnly配置在gradle中设置提供的范围。