Tomcat 8 java.lang.LinkageError:违反加载程序约束

Posted

技术标签:

【中文标题】Tomcat 8 java.lang.LinkageError:违反加载程序约束【英文标题】:Tomcat 8 java.lang.LinkageError: loader constraint violation 【发布时间】:2017-02-15 11:40:03 【问题描述】:

我正在tomcat 上部署一个Web 服务(它使用METRO 2.0 库并将其包含在war 文件中)并启用security manager

-Djava.security.manager
-Djava.security.policy=C:\apache-tomcat-8.5.6\conf\catalina.policy

我得到以下异常

    SEVERE [localhost-startStop-1] 
 com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized 
    WSSERVLET11: failed to parse runtime descriptor: java.lang.LinkageError: loader 
    constraint violation: loader (instance of 
    org/apache/catalina/loader/ParallelWebappClassLoader) previously initiated loading for a 
    different type with name "javax/xml/bind/annotation/XmlNsForm"
     java.lang.LinkageError: loader constraint violation: loader (instance of 
    org/apache/catalina/loader/ParallelWebappClassLoader) previously initiated loading for a 
    different type with name "javax/xml/bind/annotation/XmlNsForm"
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal
    (WebappClassLoaderBase.java:2268)
        at org.apache.catalina.loader.WebappClassLoaderBase
    $PrivilegedFindClassByName.run(WebappClassLoaderBase.java:155)
        at org.apache.catalina.loader.WebappClassLoaderBase
    $PrivilegedFindClassByName.run(WebappClassLoaderBase.java:144)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClass
    (WebappClassLoaderBase.java:809)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass
    (WebappClassLoaderBase.java:1254)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass
    (WebappClassLoaderBase.java:1119)
        at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl$1.<clinit>
    (PropertyInfoImpl.java:365)
        at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.calcXmlName
    (PropertyInfoImpl.java:365)
        at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.calcXmlName
    (PropertyInfoImpl.java:340)
        at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl.getTypes
    (ElementPropertyInfoImpl.java:136)
        at com.sun.xml.bind.v2.model.impl.RuntimeElementPropertyInfoImpl.getTypes
    (RuntimeElementPropertyInfoImpl.java:86)
        at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl$1.size
    (ElementPropertyInfoImpl.java:78)
        at java.util.AbstractList$Itr.hasNext(AbstractList.java:351)
        at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo
    (ModelBuilder.java:255)
        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo
    (RuntimeModelBuilder.java:100)
        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo
    (RuntimeModelBuilder.java:81)
        at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo
    (ModelBuilder.java:209)
        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo
    (RuntimeModelBuilder.java:95)
        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo
    (RuntimeModelBuilder.java:81)
        at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo
    (ModelBuilder.java:315)
        at com.sun.xml.bind.v2.model.impl.TypeRefImpl.calcRef(TypeRefImpl.java:92)
        at com.sun.xml.bind.v2.model.impl.TypeRefImpl.getTarget(TypeRefImpl.java:69)
        at com.sun.xml.bind.v2.model.impl.RuntimeTypeRefImpl.getTarget
    (RuntimeTypeRefImpl.java:58)
        at com.sun.xml.bind.v2.model.impl.RuntimeTypeRefImpl.getTarget
    (RuntimeTypeRefImpl.java:51)
        at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl$1.get
    (ElementPropertyInfoImpl.java:74)
        at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl$1.get
    (ElementPropertyInfoImpl.java:77)
        at java.util.AbstractList$Itr.next(AbstractList.java:358)
        at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo
    (ModelBuilder.java:255)
        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo
    (RuntimeModelBuilder.java:100)
        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo
    (RuntimeModelBuilder.java:81)
        at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo
    (ModelBuilder.java:209)
        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo
    (RuntimeModelBuilder.java:95)
        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo
    (RuntimeModelBuilder.java:81)
        at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo
    (ModelBuilder.java:315)
        at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo
    (ModelBuilder.java:330)
        at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet
    (JAXBContextImpl.java:466)
        at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:302)
        at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build
    (JAXBContextImpl.java:1140)
        at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
        at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:106)
        at com.sun.xml.ws.developer.JAXBContextFactory$1.createJAXBContext
    (JAXBContextFactory.java:109)
        at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run
    (AbstractSEIModelImpl.java:161)
        at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run
    (AbstractSEIModelImpl.java:154)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext
    (AbstractSEIModelImpl.java:153)
        at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess
    (AbstractSEIModelImpl.java:94)
        at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel
    (RuntimeModeler.java:258)
        at com.sun.xml.ws.server.EndpointFactory.createSEIModel
    (EndpointFactory.java:338)
        at com.sun.xml.ws.server.EndpointFactory.createEndpoint
    (EndpointFactory.java:201)
        at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:505)
        at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters
    (DeploymentDescriptorParser.java:253)
        at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse
    (DeploymentDescriptorParser.java:147)
        at 
com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized
    (WSServletContextListener.java:124)
        at org.apache.catalina.core.StandardContext.listenerStart
    (StandardContext.java:4727)
        at org.apache.catalina.core.StandardContext.startInternal
    (StandardContext.java:5189)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal
    (ContainerBase.java:724)
        at org.apache.catalina.core.ContainerBase.access$000(ContainerBase.java:129)
        at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run
    (ContainerBase.java:150)
        at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run
    (ContainerBase.java:140)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:698)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:596)
        at org.apache.catalina.startup.HostConfig$DeployDescriptor.run
    (HostConfig.java:1805)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        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)

另一方面,没有security manager - 一切正常部署。

经过一番搜索,我了解到问题在于javax/xml/bind/annotation/XmlNsFormtomcat 库和METRO 2.0 中都存在。

所以我有两个问题:

1.catalina.policy 中是否有某种属性可以设置来避免这个问题。

2.有没有其他方法可以在不从war 中删除Metro 2.0 的情况下解决此冲突。

提前致谢。

【问题讨论】:

【参考方案1】:

因此,解决方案不是使用 Metro 2.0 的整个捆绑包 - 仅使用捆绑包的一些库(添加为 jars 而不是 netbeans 中的整个捆绑包)

【讨论】:

以上是关于Tomcat 8 java.lang.LinkageError:违反加载程序约束的主要内容,如果未能解决你的问题,请参考以下文章

Tomcat 8 源码导入到IDEA

在 Tomcat 6-Java 7/8 中运行 Tomcat 6-Java 6 WebApps

CentOS源码安装 Tomcat/8.0.24

MyEclipse 8.6配置tomcat问题??

Tomcat-8.5.23 基于域名和端口的虚拟主机

Tomcat 8安装与配置