Deploying a Jersey webapp on Jboss AS 7

后端 未结 11 1131
既然无缘
既然无缘 2020-12-01 06:13

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

相关标签:
11条回答
  • 2020-12-01 06:38

    You can get past this in the standalone configuration by modifying configuration/standalone.xml and removing references to jaxrs in the extensions and profile section. Note, even though I commented those portions out in my standalone.xml, JBoss will automagically remove those references altogether on next startup...

    0 讨论(0)
  • 2020-12-01 06:39

    Can we update the "server-agnostic" approach to include JBoss 7.1.1 and Servlet 3.0?

    <context-param> is invalid in a version 3.0 web-xml.

    0 讨论(0)
  • 2020-12-01 06:51

    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

    0 讨论(0)
  • 2020-12-01 06:51

    Here is what worked for me for JBoss 7.1.1 and Jersey 1.17.1. No need to modify standalone.xml or domain.xml. Besides filtering restEasy in web.xml instruct Jersey to use Jackson. You can read about this configuration here.

    To save time in configuration guesses, I am posting web.xml and pom.xml from test project.

    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
      <display-name>TestJerseyonJBoss</display-name>
      <servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
          <param-name>com.sun.jersey.config.property.packages</param-name>
          <param-value>com.test.rest</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>Jersey REST Service</servlet-name>
        <url-pattern>/rest/*</url-pattern>
      </servlet-mapping>
       <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>
    </web-app>
    

    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>TestJerseyOnJBoss</groupId>
      <artifactId>TestJerseyOnJBoss</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>war</packaging>
      <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
              <warSourceDirectory>WebContent</warSourceDirectory>
              <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <dependencies>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-bundle</artifactId>
            <version>1.17.1</version>
        </dependency>
    
            <dependency>
               <groupId>com.sun.jersey</groupId>
               <artifactId>jersey-json</artifactId>
               <version>1.17.1</version>
            </dependency>
        <dependency>
                   <groupId>asm</groupId>
                   <artifactId>asm</artifactId>
                   <version>3.3.1</version>
                   <type>jar</type>
                   <scope>compile</scope>
        </dependency>
      </dependencies>
    

    0 讨论(0)
  • 2020-12-01 06:53
     <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.:-)

    0 讨论(0)
  • 2020-12-01 06:58

    You should exclude jaxrs subsystem from being activated for your deployment add this into META-INF/jboss-deployment-structure.xml

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

    or you can go to standalone.xml and remove subsystem there. To do so, you need to remove

    <subsystem xmlns="urn:jboss:domain:jaxrs:1.0">
    ...
    ...
    <subsystem>
    

    part of configuration, extension part of on top can stay it wont hurt either way. or you can connect to server with CLI and run

    /subsystem=webservices:remove()
    

    Just a note, exclude-subsystems functionality and deployment-strucure:1.2 was added in 7.1.2 and as such will not work on on 7.1.1.

    0 讨论(0)
提交回复
热议问题