0

I am trying to use Jersey to create a RESTful API. My pom.xml looks like:

<!-- Jersey Library -->
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.18</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-bundle</artifactId>
            <version>1.18</version>
        </dependency>
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
            <version>3.3.1</version>
        </dependency>

But I get Only one JAX-RS Application Class allowed. exception while deploying the application in Jboss. However, this works very well in case of tomcat.

Stacktrace:

ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."apiinterface.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."apiinterface.war".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of deployment "apiinterface.war"
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:127) [jboss-as-server-7.2.0.Final-redhat-4.jar:7.2.0.Final-redhat-4]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
        at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011232: Only one JAX-RS Application Class allowed.  com.sun.jersey.api.core.ClasspathResourceConfig com.sun.jersey.api.core.DefaultResourceConfig com.sun.jersey.server.impl.application.DeferredResourceConfig com.sun.jersey.api.core.servlet.WebAppResourceConfig com.sun.jersey.api.core.DefaultResourceConfig com.sun.jersey.api.core.ApplicationAdapter com.sun.jersey.api.core.ClassNamesResourceConfig com.sun.jersey.api.core.ResourceConfig com.sun.jersey.api.core.ApplicationAdapter com.sun.jersey.api.core.ClasspathResourceConfig com.sun.jersey.server.impl.application.DeferredResourceConfig com.sun.jersey.api.core.ScanningResourceConfig com.sun.jersey.api.core.ScanningResourceConfig com.sun.jersey.api.core.PackagesResourceConfig com.sun.jersey.api.core.ClassNamesResourceConfig com.sun.jersey.api.core.PackagesResourceConfig com.sun.jersey.api.core.ResourceConfig
        at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scan(JaxrsScanningProcessor.java:206)
        at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:104)
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:120) [jboss-as-server-7.2.0.Final-redhat-4.jar:7.2.0.Final-redhat-4]
        ... 5 more

I tried implementing answers from Deploying a Jersey webapp on Jboss AS 7 but no success so far.

Community
  • 1
  • 1
nebula
  • 3,932
  • 13
  • 53
  • 82
  • I wanted to default to Jersey too, but I can testify that the built-in RestEasy works equally well. Especially when you upgrade it to the latest version, which is quite easy to do. Just be sure to not mistakenly pick the JBoss 8 version like I did :s – Gimby Feb 04 '14 at 08:37

2 Answers2

5

JBoss AS / EAP already provides you with a JAX-RS implementation (RESTEasy), so your pom.xml should only contain a dependency on the JAX-RS API (with scope provided).

If you want to build and deploy on Tomcat and/or JBoss AS, you should use Maven profiles and include Jersey artefacts in the Tomcat profile only.

Xavier Coulon
  • 1,580
  • 10
  • 15
  • I tried using only `JAX-RS API` with scope `provided` but my application has some imports from `com.sun.jersey.api.*` and `com.sun.jersey.spi.*`. How can this be managed then? – nebula Feb 04 '14 at 09:19
  • 1
    Then I guess you'd need to exclude the JAX-RS modules provided by JBoss AS for your application when it is deployed (on JBoss AS). The you can keep your dependencies as you initially did. See https://community.jboss.org/thread/215838 for the jboss-deployment-structure.xml config file you need to include in your application – Xavier Coulon Feb 04 '14 at 14:32
0

JBoss does not support Jersey Out Of the Box, it has it's own implementation RestEasy, In order to make Jersey Work, either we need to disable Jersey in standalone.xml, and enable ReastEasy support.

kanaparthikiran
  • 523
  • 12
  • 15