Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying a Jersey webapp on Jboss AS 7

Currently running some webapps on Jboss AS 4/5 and I am testing migration to jboss7. When I try to deploy a jersey based webapp on JBoss AS 7 (full profile with standalone-preview config file), I get:

org.jboss.as.server.deployment.DeploymentUnitProcessingException: Only one JAX-RS Application Class allowed.

I've done a bit of hunting around on it and found that RestEasy is the default JAX-RS implementation embedded into Application Server. Posts like http://community.jboss.org/message/579996 and https://issues.jboss.org/browse/JBAS-8830) mention that the RestEasy deployer takes over.

In AS 6, it seems easier to remove the deployer whereas I have not seen any solutions for AS 7.

like image 824
DOS Avatar asked Aug 05 '11 08:08

DOS


People also ask

How do you deploy a WAR in JBoss EAP 7?

From the JBoss bin directory, run the command jboss-cli --connect to start the JBoss CLI and connect to the application server. Run the /deployment command on the compressed WAR file or exploded WAR folder. [If you are deploying to a managed domain, also run the /server-group command.]

How can you deploy an application in JBoss?

Search for the JBoss server instance to which to deploy the EAR or WAR. On the details page for the selected JBoss server instance, open the Inventory tab. In the Create New drop-down menu, select the item for - Web Application (WAR) or - Enterprise Application (EAR), as appropriate.

Can we deploy WAR file in JBoss?

If we already have the war file and we want to deploy it on JBoss, we can go to the JBoss installation directory at standalone/deployments and paste the file there. There are two modes in which the deployment works: manual: the deployment scanner will not attempt to directly monitor the deployment folder.


7 Answers

it has already been mentioned in this post : https://community.jboss.org/message/744530#744530 , you can just ask the resteasy module to not scan for other JAX RS implementations in your webapp; just add this to 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>

worked fine for me

like image 88
Anthony Dahanne Avatar answered Sep 30 '22 06:09

Anthony Dahanne


Besides removing the entire jaxrs subsystem in standalone.xml as mentioned in the other posts excluding the RESTEasy modules in jboss-deployment-structure.xml may also work.

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
  <deployment>
    <exclusions>
      <module name="org.jboss.resteasy.resteasy-atom-provider" />
      <module name="org.jboss.resteasy.resteasy-cdi" />
      <module name="org.jboss.resteasy.resteasy-jaxrs" />
      <module name="org.jboss.resteasy.resteasy-jaxb-provider" />
      <module name="org.jboss.resteasy.resteasy-jackson-provider" />
      <module name="org.jboss.resteasy.resteasy-jsapi" />
      <module name="org.jboss.resteasy.resteasy-multipart-provider" />
      <module name="org.jboss.resteasy.async-http-servlet-30" />
    </exclusions>
  </deployment>
</jboss-deployment-structure>

Also check out

  • JBoss Deployment Structure File
  • Implicit module dependencies for deployments
like image 38
Philippe Marschall Avatar answered Sep 30 '22 06:09

Philippe Marschall


 <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
  <deployment>
    <exclude-subsystems>
    <subsystem name="jaxrs" />
    </exclude-subsystems>
   </deployment>
 </jboss-deployment-structure>

Will do the trick, works great with 7.3AS.ctomc just missed a tiny slash in the end to terminate the section.:-)

like image 28
user3533685 Avatar answered Sep 30 '22 05:09

user3533685


I believe the correct approach is to use app server agnostic JAX-RS application deployment. No need to mess with any JBoss configuration. All you need is, extend javax.ws.rs.core.Application in your JAX-RS web application. You can find an example here. Then, you need to put this in your web.xml.

<servlet>
  <servlet-name>Jersey Web Application</servlet-name>
  <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
  <init-param>
    <param-name>javax.ws.rs.Application</param-name>
    <param-value>jersey.MyApplication</param-value>
  </init-param>
  <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>

  <load-on-startup>1</load-on-startup>
</servlet>

Package scanning mechanism does not work correctly on JBoss 7.x. I have tested this approach successfully in JBoss 7.0.2.Final and JBoss 7.1.1.Final.

like image 38
Arul Dhesiaseelan Avatar answered Sep 30 '22 07:09

Arul Dhesiaseelan


I managed to run Jersey WS on my JBOSS AS7.

What i do for JBOSS is just remove everything related to jax-rs in standalone.xml

My jersey sample code got from: http://www.ibm.com/developerworks/web/library/wa-aj-tomcat/

The only thing i do for the jersey is remove the init-param from web.xml and copy jersey lib to WebContent/WEB-INF/lib.

  <!--<init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>sample.hello.resources</param-value>
  </init-param>-->
like image 44
Jason Avatar answered Sep 30 '22 07:09

Jason


In web.xml file add the files

        <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>

 and comment out the init-param
        <!-- <init-param>
                  <param-name>com.sun.jersey.config.property.packages</param-name>
                  <param-value></param-value>
        </init-param> -->

This worked out for me in jboss-as-7.1.1.Final and i did not do any changes in standalone.xml.
like image 38
Raju Cluster Avatar answered Sep 30 '22 06:09

Raju Cluster


Ahother option:

  1. Edit standalone/configuration/standalone.xml and comments out all jaxrs entries. This will configure Jersey instead of RESTEasy.
  2. Remove jboss-web.xml from WEB-INF/web.xml. This file no longers works with JBoss 7
  3. Edit web.xml, add an init-param com.sun.jersey.config.property.packages configured to your resource's package, like:

    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>org.foo</param-value>
    </init-param>
    

https://github.com/Atmosphere/atmosphere/wiki/Deploying-Atmosphere-Jersey-in-JBoss-7.1.x

like image 44
Ignacio Rubio Avatar answered Sep 30 '22 07:09

Ignacio Rubio