开发者

How can I solve "java.lang.LinkageError: loader constraint violation" during execute Jersey 1.6 & axis2 1.3 in one web application?

I already have soap based web service running with axis2 1.3. These day, we have a plan to develop RESTful web service using Jersey 1.6.

I made web application( war file ) with axis2 1.3 and Jersey 1.6 and try to deploy it on jboss5.1.0.

After start jboss I saw below error message.

com.sun.jersey.api.container.ContainerException: Unable to create resource
    at com.sun.jersey.server.impl.resource.SingletonFactory$Singleton.init(SingletonFactory.java:139)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$9.f(WebApplicationImpl.java:533)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$9.f(WebApplicationImpl.java:531)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.getResourceComponentProvider(WebApplicationImpl.java:531)
.....
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.sun.jersey.server.spi.component.ResourceComponentConstructor._construct(ResourceComponentConstructor.java:200)
    at com.sun.jersey.server.spi.component.ResourceComponentConstructor.construct(ResourceComponentConstructor.java:182)
    at com.sun.jersey.server.impl.resource.SingletonFactory$Singleton.init(SingletonFactory.java:137)
    ... 87 more
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "javax.xml.bind.JAXBElement.<init>(Ljavax/xml/namespace/QName;Ljava/lang/Class;Ljava/lang/Object;)V" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, com/sun/jersey/server/wadl/WadlGeneratorImpl, and the class loader (instance of <bootloader>) for resolved class, javax/xml/bind/JAXBElement, have different Class objects for the type javax/xml/namespace/QName used in the signature
    at com.sun.jersey.server.wadl.WadlGeneratorImpl.createResponse(WadlGeneratorImpl.java:194)
    at com.sun.jersey.server.wadl.WadlBuilder.generateResponse(WadlBuilder.java:397)
    at com.sun.jersey.server.wadl.WadlBuilder.generateMethod(WadlBuilder.java:166)
    at com.sun.jersey.server.wadl.WadlBuilder.generateResource(WadlBuilder.java:308)
    at com.sun.jersey.server.wadl.WadlBuilder.generateResource(WadlBuilder.java开发者_StackOverflow:271)
    at com.sun.jersey.server.wadl.WadlBuilder.generate(WadlBuilder.java:107)
    at com.sun.jersey.server.impl.wadl.WadlApplicationContextImpl.getApplication(WadlApplicationContextImpl.java:76)
    at com.sun.jersey.server.impl.wadl.WadlResource.<init>(WadlResource.java:76)
    ... 94 more
14:23:18,155 ERROR [[/oasapi]] Servlet /oasapi threw load() exception
java.lang.LinkageError: loader constraint violation: when resolving method "javax.xml.bind.JAXBElement.<init>(Ljavax/xml/namespace/QName;Ljava/lang/Class;Ljava/lang/Object;)V" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, com/sun/jersey/server/wadl/WadlGeneratorImpl, and the class loader (instance of <bootloader>) for resolved class, javax/xml/bind/JAXBElement, have different Class objects for the type javax/xml/namespace/QName used in the signature
    at com.sun.jersey.server.wadl.WadlGeneratorImpl.createResponse(WadlGeneratorImpl.java:194)
    at com.sun.jersey.server.wadl.WadlBuilder.generateResponse(WadlBuilder.java:397)
    at com.sun.jersey.server.wadl.WadlBuilder.generateMethod(WadlBuilder.java:166)
.....

Who can teach me what is problem and how I can solve this problem ?

Thanks


There are two versions of the javax.xml.namespace.QName class being provided in your environment:

  1. The first is in Java SE 6.
  2. The second appears to be provided by JBoss


I think you have problem with jar files dependencies. If you are using maven try to find out which library conflicts, I do it with maven's :~$ mvn dependency:tree That will output some lines of text like:

[INFO] [dependency:tree {execution: default-cli}]
[INFO] org.braman.app:jersey-rest-wadl:war:1.0-SNAPSHOT
[INFO] +- log4j:log4j:jar:1.2.12:provided
[INFO] +- com.sun.jersey:jersey-server:jar:1.8:compile
[INFO] |  +- asm:asm:jar:3.1:compile
[INFO] |  \- com.sun.jersey:jersey-core:jar:1.8:compile
[INFO] +- com.sun.jersey:jersey-json:jar:1.8:compile
[INFO] |  +- org.codehaus.jettison:jettison:jar:1.1:compile
[INFO] |  +- org.codehaus.jackson:jackson-core-asl:jar:1.7.1:compile
[INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.7.1:compile
[INFO] |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.7.1:compile
[INFO] |  \- org.codehaus.jackson:jackson-xc:jar:1.7.1:compile
[INFO] \- javax.servlet:servlet-api:jar:2.5:provided

And from this output I can analyze the library dependencies. By the way this is sample maven pom.xml:

<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>org.braman.app</groupId>
    <artifactId>jersey-rest-wadl</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Jersey Restful Service WADL Example</name>
    <properties>
        <junit.version>3.8.1</junit.version>
        <log4j.version>1.2.12</log4j.version>
        <jersey.version>1.8</jersey.version>
        <servlet_api.version>2.5</servlet_api.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>${jersey.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>stax</groupId>
                    <artifactId>stax-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>${jersey.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.xml.bind</groupId>
                    <artifactId>jaxb-impl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>stax</groupId>
                    <artifactId>stax-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>${servlet_api.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>maven2-repository.java.net</id>
            <name>Java.net Repository for Maven</name>
            <url>http://download.java.net/maven/2</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>wadl-repository</id>
            <name>WADL Maven Repository</name>
            <url>https://wadl.dev.java.net/nonav/repository/</url>
        </repository>
    </repositories>
    <build>
        <finalName>jrw</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jboss-maven-plugin</artifactId>
                <version>1.5.0</version>
                <configuration>
                    <jbossHome>/data/Work/servers/jboss/jboss-5.1.0.GA</jbossHome>
                    <serverName>default</serverName>
                    <fileName>target/jrw.war</fileName>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

I hope it will help you.


I noticed this issue with Jersey 1.5 (making a REST XML feed in JBoss 5) and upgrading to Jersey 1.9 solved it.


I had a similar issue. I found out that there were a conflict between the jaxb libraries provided by jersey and the ones provided by jboss.

Here is below the relevant part of my pom.xml that solved my problem. Note I use the jersey 1.9 as @Jon state in his answer.

    ...
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.9</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.9</version>
        <exclusions>
            <exclusion>
                <artifactId>jaxb-api</artifactId>
                <groupId>javax.xml.bind</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jaxb-impl</artifactId>
                <groupId>com.sun.xml.bind</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    ...

JBoss 5.1.0
Jersey 1.9


<dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.12</version>
        <exclusions>
            <exclusion>
                <groupId>stax</groupId>
                <artifactId>stax-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜