Search code examples
javajbossjerseyjboss7.xjersey-2.0

Jersey 2 on Jboss 7


Has anyone had success deploying Jersey 2.x with JBoss 7.x? I've tried deploying Jersey 2.5 with JBoss 7.1.1 but encountered errors like:

"java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;"

I believe this issue is because JBoss comes bundled with RestEasy which is a JAX-RS 1.0 implementation while Jersey is a JAX-RS 2.0 implementation. So I took the following steps to disable RestEasy:

1) Added the following to my web.xml:

<context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>resteasy.scan.providers</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>resteasy.scan.resources</param-name>
    <param-value>false</param-value>
</context-param>

2) Followed the discussion here, I modified my JBoss' standalone.xml, module.xml, and domain.xml to remove all references to JAXRS1.1 / RestEasy.

3) This led to another error: "java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor" which I resolved by adding the following to my pom.xml:

<dependency>
    <groupId>asm</groupId>
    <artifactId>asm</artifactId>
    <version>3.3.1</version>
</dependency>

So finally my app deploys without errors but now I cannot seem to access any of my Jersey resources. Jetty 8 works fine, however. I also was able to run Jersey 1.x without having to take steps #2 and #3 but I would prefer to use Jersey 2.x if possible.

Additionally I've also tried creating a jboss-deployment-structure.xml file, but then I still encounter the previous errors like "java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;"

<?xml version="1.0" encoding="UTF-8"?>  
<jboss-deployment-structure>
  <deployment>
    <exclusions>
            <module name="org.jboss.resteasy.resteasy-atom-provider"/>  
            <module name="org.jboss.resteasy.resteasy-cdi"/>  
            <module name="org.jboss.resteasy.resteasy-jackson-provider"/>  
            <module name="org.jboss.resteasy.resteasy-jaxb-provider"/>  
            <module name="org.jboss.resteasy.resteasy-jaxrs"/>  
            <module name="org.jboss.resteasy.resteasy-jettison-provider"/>  
            <module name="org.jboss.resteasy.resteasy-jsapi"/>  
            <module name="org.jboss.resteasy.resteasy-multipart-provider"/>  
            <module name="org.jboss.resteasy.resteasy-yaml-provider"/>  
            <module name="org.apache.log4j"/>  
            <module name="org.apache.commons.pool"/>  
            <module name="javax.ws.rs.api"/>
    </exclusions>
  </deployment>
</jboss-deployment-structure>

Has anyone had any luck with Jboss and Jersey 2.x? Any help would be appreciated.


Solution

  • You can use Jersey 2 on JBoss 7 if you configure your jboss-deployment-structure.xml similar to this:

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
    <deployment>
    
    <exclude-subsystems>
      <subsystem name="resteasy" />
    </exclude-subsystems>
    
    <exclusions>
      <module name="javaee.api" />
      <module name="javax.ws.rs.api"/>
      <module name="org.jboss.resteasy.resteasy-jaxrs" />
    </exclusions>
    
    <local-last value="true" />
    
    </deployment>
    </jboss-deployment-structure>
    

    Because JBoss 7 includes dependencies of modules, it is not sufficient to exclude the resteasy module itself but you need to exclude the whole javaee.api module. Also make sure to not exclude too many modules. This may also break your application - the example above is sufficient to disable resteasy.

    As you already discovered, you still need to include the following lines in your web.xml

      <context-param>
       <param-name>resteasy.scan</param-name>
       <param-value>false</param-value>
      </context-param>
      <context-param> 
       <param-name>resteasy.scan.providers</param-name>
       <param-value>false</param-value>
      </context-param>
      <context-param>
       <param-name>resteasy.scan.resources</param-name>
       <param-value>false</param-value>
      </context-param>