How can I solve "java.lang.LinkageError: violation of the bootloader restriction" while running Jersey 1.6 and axis2 1.3 in the same web application?

I already have a soap-based web service that works with the 1.3 axis. On this day, we have a RESTful web service development plan using Jersey 1.6.

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

After starting 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: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 a problem, and how can I solve this problem?

thanks

+8
jersey jboss jaxb axis2
source share
5 answers

Two versions of the javax.xml.namespace.QName class are provided in your environment:

  • The first is in Java SE 6.
  • The second information is provided by JBoss.
+4
source share

I think you have problems with jar file dependencies. If you are using maven, try to figure out which library conflicts, I do this with maven: ~ $ mvn dependency:tree This will print some lines of text, for example:

 [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 conclusion, I can analyze the library dependencies. By the way, this is an example of 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> 

Hope this helps you.

+1
source share

I noticed this problem with Jersey 1.5 (by creating a REST XML feed in JBoss 5), and upgrading to Jersey 1.9 solved it.

+1
source share

I had a similar problem. I found out that there is a conflict between jaxb libraries provided by jersey and those provided by jboss.

Below is the relevant part of my pom.xml that solved my problem. Note. I am using jersey 1.9 as @Jon condition in my 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

+1
source share
 <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
source share

All Articles