Creating a module in jBoss AS

Im uses jBoss AS 7 to publish my various projects, and they all use the Jersey API, so instead of deploying to each project, I wanted to create a module for it. To do this, I created the JBOSS_HOME \ modules \ com \ sun \ Jersey \ main folder, and in this folder I placed the Jersey cans and the module.xml file:

<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="com.sun.jersey"> <properties> <property name="jboss.api" value="private"/> </properties> <resources> <resource-root path="jersey-bundle-1.12.jar"/> <resource-root path="asm-3.1.jar"/> <resource-root path="jackson-core-asl-1.9.2.jar"/> <resource-root path="jackson-jaxrs-1.9.2.jar"/> <resource-root path="jackson-mapper-asl-1.9.2.jar"/> <resource-root path="jackson-xc-1.9.2.jar"/> <resource-root path="jersey-client-1.12.jar"/> <resource-root path="jersey-core-1.12.jar"/> <resource-root path="jersey-json-1.12.jar"/> <resource-root path="jersey-server-1.12.jar"/> <resource-root path="jersey-servlet-1.12.jar"/> <resource-root path="jettison-1.1.jar"/> <resource-root path="jsr311-api-1.1.1.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="org.jboss.staxmapper"/> <module name="org.jboss.as.controller"/> <module name="org.jboss.as.server"/> <module name="org.jboss.modules"/> <module name="org.jboss.msc"/> <module name="org.jboss.logging"/> <module name="org.jboss.vfs"/> </dependencies> </module> 

To prevent the use of jBoss JAX-RS, I deleted the following lines from the JBOSS_HOME \ standalone \ standalone.xml file:

 <subsystem xmlns="urn:jboss:domain:jaxrs:1.0"/> <extension module="org.jboss.as.jaxrs"/> 

In the MyProjectEAR \ META-INF folder, I created a jboss-deployment-structure.xml file with the following structure:

 <?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"> <deployment> <dependencies> <module name="com.sun.jersey" slot="main" > <imports> <include path="META-INF/**"/> <include path="**"/> </imports> </module> </dependencies> </deployment> </jboss-deployment-structure> 

My file is MyProject \ webContent \ web.xml:

 <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name> MyProject </display-name> <servlet> <description> </description> <servlet-name>Jersey Servlet</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <description></description> <param-name>javax.ws.rs.Application</param-name> <param-value>com.MyProject.service.REST_Application</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey Servlet</servlet-name> <url-pattern>/jaxrs/*</url-pattern> </servlet-mapping> </web-app> 

My manifest file is present in MyProject \ webContent \ META-INF \ MANIFEST.MF:

 Manifest-Version: 1.0 Class-Path: 

When I tried to deploy the project, I got the following error:

 12:12:11,804 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015876: Starting deployment of "MyProjectEAR.ear" 12:12:11,852 INFO [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015876: Starting deployment of "MyProject.war" 12:12:12,052 WARN [org.jboss.as.dependency.private] (MSC service thread 1-3) JBAS018567: Deployment "deployment.MyProjectEAR.ear" is using a private module ("com.sun.jersey:main") which may be changed or removed in future versions without notice. 12:12:12,054 WARN [org.jboss.as.dependency.private] (MSC service thread 1-3) JBAS018567: Deployment "deployment.MyProjectEAR.ear" is using a private module ("com.sun.jersey:main") which may be changed or removed in future versions without notice. 12:12:12,055 WARN [org.jboss.as.dependency.private] (MSC service thread 1-3) JBAS018567: Deployment "deployment.MyProjectEAR.ear" is using a private module ("com.sun.misc:main") which may be changed or removed in future versions without notice. 12:12:12,057 WARN [org.jboss.as.dependency.private] (MSC service thread 1-3) JBAS018567: Deployment "deployment.MyProjectEAR.ear" is using a private module ("com.sun.misc:main") which may be changed or removed in future versions without notice. 12:12:12,117 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC00001: Failed to start service jboss.deployment.subunit."MyProjectEAR.ear"."MyProject.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."MyProjectEAR.ear"."MyProject.war".POST_MODULE: Failed to process phase POST_MODULE of subdeployment "MyProject.war" of deployment "MyProjectEAR.ear" at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final] at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA] at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [rt.jar:1.6.0_30] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.6.0_30] at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_30] Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011093: Could not load component class com.sun.jersey.spi.container.servlet.ServletContainer at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:113) at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:54) at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final] ... 5 more Caused by: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer from [Module "deployment.MyProjectEAR.ear.MyProject.war:main" from Service Module Loader] at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA] at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA] at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA] at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA] at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA] at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:111) ... 7 more 12:12:12,340 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "MyProjectEAR.ear" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.deployment.subunit.\"MyProjectEAR.ear\".\"MyProject.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"MyProjectEAR.ear\".\"MyProject.war\".POST_MODULE: Failed to process phase POST_MODULE of subdeployment \"MyProject.war\" of deployment \"MyProjectEAR.ear\""}} 12:12:12,351 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015877: Stopped deployment MyProject.war in 9ms 12:12:12,353 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015877: Stopped deployment MyProjectEAR.ear in 12ms 12:12:12,355 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report JBAS014777: Services which failed to start: service jboss.deployment.subunit."MyProjectEAR.ear"."MyProject.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."MyProjectEAR.ear"."MyProject.war".POST_MODULE: Failed to process phase POST_MODULE of subdeployment "MyProject.war" of deployment "MyProjectEAR.ear" 12:12:12,359 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.deployment.subunit.\"MyProjectEAR.ear\".\"MyProject.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"MyProjectEAR.ear\".\"MyProject.war\".POST_MODULE: Failed to process phase POST_MODULE of subdeployment \"MyProject.war\" of deployment \"MyProjectEAR.ear\""}}}} 

* EDIT: * If I put the Jersey API in JBOSS_HOME \ modules \ com \ sun \ jsf-impl \ main and change the corresponding module.xml, everything will work fine. What is different about this location?

+8
java jersey deployment configuration
source share
7 answers

I needed to add

 <subsystem xmlns="urn:jboss:domain:ee:1.0"> <global-modules> <module name="com.sun.jersey" slot="main"/> </global-modules> </subsystem> 

to the configuration file JBOSS_HOME \ standalone \ configuration \ standalone.xml

+7
source share

You need to specify the dependency on your module in the deployment.

META-INF \ MANIFEST.MF

 Dependencies: com.sun.jersey 

See also https://docs.jboss.org/author/display/AS71/Class+Loading+in+AS7

+12
source share

There is already an answer, but I would like to clarify this topic a little for future readers.

There are three places to declare a JBoss module as a dependency on other deployments in JBoss 7 (EAP 6):

  • Global modules
  • MANIFEST.MF
  • JBoss deployment-structure.xml

In most cases, they are alternative.

1. Global modules

A global module is a module that the JBoss Enterprise Application Platform 6 provides as a dependency on each application. Any module can be made global by adding it to the list of application servers of global modules.

You can easily add global modules from the management console (see sources) or edit the standalone.xml file:

 <subsystem xmlns="urn:jboss:domain:ee:1.0" > <global-modules> <!-- Add global modules here --> <module name="org.javassist" slot="main" /> </global-modules> </subsystem> 

2. MANIFEST.MF

Add a Dependencies entry to the MANIFEST.MF file with a comma-separated list of dependency module names.

 Dependencies: org.javassist, org.apache.velocity 

If you are using Maven, you just need to configure some plugins. for example, for hearing.

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-ear-plugin</artifactId> <configuration> <version>6</version> ... <defaultLibBundleDir>lib</defaultLibBundleDir> <archive> <manifestEntries> <Dependencies> com.foo.bar.test-module export optional <!-- Beware of new lines! They can quietly break the conf --> </Dependencies> </manifestEntries> </archive> <modules> ... </modules> </configuration> </plugin> 

NOTE: using export makes com.foo.bar.test-module visible to all modules included in the ear.

3. JBoss deployment-structure.xml

jboss-deployment-structure.xml is a descriptive JBoss deployment descriptor that can be used to control class loading in a fine-grained way. It must be hosted in a top-level deployment, in META-INF (or WEB-INF for deployment on the Internet)

Below you can see how much it compares with MANIFEST.MF. For the simplest case, here is an example:

 <?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <ear-subdeployments-isolated>false</ear-subdeployments-isolated> <deployment> <dependencies> <!-- Add modules here --> <module name="com.foo.bar.test-module" export="true"/> <module name="org.apache.axis.axis-jaxrpc" export="true"/> </dependencies> </deployment> </jboss-deployment-structure> 

NOTE 1: just like using MANIFEST.MF, setting export=true displays com.foo.bar.test-module for all modules included in the ear.

NOTE 2. The optional=true/false attribute is also available in jboss-deployment-structure.xml, but does not work properly for certain versions (probably <EAP 6.4.7). Check it out if you need it.

Hope this helps.

Sources

RedHat docs - adding an explicit module dependency to a deployment

RedHat docs - Configuring Modules

RedHat docs - adding a module to all deployments

JBoss AS 7 Developer's Guide

+3
source share

If you are using Maven, you can add a module reference in JBoss AS as follows:

 <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.2</version> <configuration> <archive> <manifestEntries> <!-- List your dependencies here --> <Dependencies>com.sun.jersey</Dependencies> </manifestEntries> </archive> </configuration> </plugin> 

That will automatically generate manifest entries for you.

I personally have to use this approach to avoid the "Native Library xxxxxxx already loaded in another loader" error when loading com.microsoft.jdbc.sqlserver.SQLServerDriver, which I defined as a module in JBoss AS. Thus, JNDI defined connections can connect to MSSQL, and at the same time, I can reuse this dependency to connect directly to the database (this time through DriverManager instead of JNDI).

+2
source share

I'm not an expert on jboss-modules, but there are a few things you could try.

You said put all the JAR and module.xml in JBOSS_HOME\modules\com\sun\Jersey\main . Pay attention to capital J. I don’t know that it matters, but for consistency, at least you can make it more strict.

Also I don't think you want <include path="**"/> in jboss-deployment-structure.xml .

Again, I could be wrong, as I am definitely not an expert on jboss-modules, but first I will try these two things.

0
source share

Comment on the init parameter in the web.xml file that really worked ...

 <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name> MyProject </display-name> <servlet> <description> </description> <servlet-name>Jersey Servlet</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <!-- <init-param> <description></description> <param-name>javax.ws.rs.Application</param-name> <param-value>com.MyProject.service.REST_Application</param-value> </init-param>--> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey Servlet</servlet-name> <url-pattern>/jaxrs/*</url-pattern> </servlet-mapping> </web-app> 
0
source share

Global modules can also be added through the CLI.

This makes changes easier since you can create a batch file and run it. / jboss -cli.sh --file {file path}

0
source share

All Articles