JBoss AS 7 modules: can do a module with all libraries in a directory? - jboss

I want to define a module with a resource-root like this:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mymodule">
<resources>
<resource-root path="libs"/>
</resources>
<dependencies />
</module>
The directory contains all the libraries I need.
I've tried it and it not work, but if I put it this way it work:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mymodule">
<resources>
<resource-root path="libs/lib1.jar"/>
<resource-root path="libs/lib2.jar"/>
<resource-root path="libs/lib3.jar"/>
<resource-root path="libs/lib4.jar"/>
........
</resources>
<dependencies />
</module>
Is there a way to do it the first?

Try and use libs.* in your first implementation
UPDATE:
This feature is not currently available, though its under R&D
If you need to include multiple jars in a module, you will need to instantiate each indivisually

I know this one is old, but I just had the same problem on EAP-7 and solved it as follows:
You may want to create the module using the JBoss CLI. My problem was to supply multiple resources as it was yours. I am using the attribute resource-delimiter and provide my list of resources as follows:
module add --name=my.module --resource-delimiter=, --resources=libA.jar,libB.jar,libC.jar --dependencies=my.dep.a,my.dep.b
This generates the following module.xml in the respective JBoss folder:
<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="my.module">
<resources>
<resource-root path="libA.jar"/>
<resource-root path="libB.jar"/>
<resource-root path="libC.jar"/>
</resources>
<dependencies>
<module name="my.dep.a"/>
<module name="my.dep.b"/>
</dependencies>
</module>
Hope it helps.

Related

How to force wildfly-8.2.1.Final to load .class from a directory rather than war?

I want load .class file from a given directory so, i put compiled file inside the directory /opt/wildfly-8.2.1.Final/modules/packagename/ and also server load the classes from the same directory rather than war(WEB-INF/classes/packagename/).
I haven't tried this method myself, but you must:
Move /opt/wildfly-8.2.1.Final/modules/packagename/ to
/opt/wildfly-8.2.1.Final/modules/custom-classes/main/packagename/
Add file module.xml to
/opt/wildfly-8.2.1.Final/modules/custom-classes/main/
Add file jboss-deployment-structure.xml to your war.
Undeploy the war, restart the server and then redeploy the war.
Content of module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="custom-classes">
<resources>
<resource-root path="."/>
</resources>
</module>
Contents of jboss-deployment-structure.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="custom-classes" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Edit: If you want to add jars as well as non-jared classes to your module you must not only copy jars to /opt/wildfly-8.2.1.Final/modules/custom-classes/main/, but also list jars in module.xml like this:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="custom-classes">
<resources>
<resource-root path="."/>
<resource-root path="dependency1.jar"/>
<resource-root path="dependency2.jar"/>
<!-- and so on for other jars -->
</resources>
</module>
Resources:
Class Loading in WildFly
How to write jboss-deployment-structure.xml
How to ad directory to JBoss classpath

JBOSS EAP 7.0 - java.lang.NoClassDefFoundError:org/springframework/context/support/ClassPathXmlApplicationContext

I am currently migrating apps from JBoss 5.1 to JBoss 7.0 EAP server.
I have added a module to JBoss server named - org.springframework for spring dependency jars
<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="org.springframework">
<resources>
<resource-root path="spring-core-3.0.5.RELEASE.jar"/>
<resource-root path="spring-context-3.0.5.RELEASE.jar"/>
<resource-root path="spring-beans-3.0.5.RELEASE.jar"/>
<resource-root path="spring-expression-3.0.5.RELEASE.jar"/>
<resource-root path="spring-web-3.0.5.RELEASE.jar"/>
<resource-root path="spring-aop-3.0.5.RELEASE.jar"/>
<resource-root path="spring-asm-3.0.5.RELEASE.jar"/>
<resource-root path="spring-jdbc-3.0.5.RELEASE.jar"/>
<resource-root path="spring-tx-3.0.5.RELEASE.jar"/>
<resource-root path="org.springframework.web.servlet-3.0.0.M3.jar"/>
<resource-root path="commons-logging-1.1.1.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.servlet.jsp.api"/>
<module name="javax.faces.api"/>
</dependencies>
</module>
I have defined the module dependency in jboss-deployment-structure.xml of the WAR
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.oracle" />
<module name="org.springframework" />
</dependencies>
</deployment>
</jboss-deployment-structure>
The war deployed to server also contains spring-context-3.0.5.RELEASE.jar in its WEB-INF/lib folder
So I think the required jar - spring-context-3.0.5.RELEASE.jar exists in class path. But still I am getting the below error :
04:33:30,496 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (default task-19) Loading XML bean definitions from class path resource [core_services.xml]
04:33:30,507 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (default task-19) Pre-instantiating singletons in org.springframework.beans.fact
ory.support.DefaultListableBeanFactory#9b765aa: defining beans [LogService,CacheService,PropertyService]; root of factory hierarchy
2017.02.09 04:33:30 ERROR CashViewsPortalServiceImpl(-2): org/springframework/context/support/ClassPathXmlApplicationContext
CallStack=java.lang.NoClassDefFoundError: org/springframework/context/support/ClassPathXmlApplicationContext
at com.karthik.common.service.Services.getService(Services.java:31)
at com.karthik.data.service.DataServices.getService(DataServices.java:18)
at com.karthik.portal.server.PortalServiceImpl.getInitializeInfo(PortalServiceImpl.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:265)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:305)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
1) Why do we need add module in Jboss 7 EAP server for class loading even though the jars are bundled in WEB-INF/lib folder of the war
deployed on server?
2) How to resolve the above error?
I think you have n't defined the spring dependencies perfectly. Below are the steps:
You can define Spring as a module
The following are steps to create a Spring module:
1.Download the desired version of Spring. For this example we are using Spring 3.1.1.
2.Create the directory: $JBOSS_HOME/modules/org/springframework/spring/main.
3.Copy the Spring libraries you downloaded to that directory.
4.Create module.xml with the following contents under that directory. Make sure these correspond to the libraries' names:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.springframework.spring">
<resources>
<resource-root path="org.springframework.aop-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.asm-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.aspects-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.beans-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.context-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.context.support-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.core-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.expression-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.instrument-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.instrument.tomcat-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.jdbc-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.jms-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.orm-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.oxm-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.test-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.transaction-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.web-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.web.portlet-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.web.servlet-3.1.1.RELEASE.jar"/>
<resource-root path="org.springframework.web.struts-3.1.1.RELEASE.jar"/>
</resources>
<dependencies>
<module name="org.apache.commons.logging"/>
<module name="javax.api" export="true"/>
<module name="org.jboss.vfs"/>
</dependencies>
</module>
Here is an absolute minimal module.xml (the different Spring version is irrelevant):
<?xml version="1.0"?>
<module xmlns="urn:jboss:module:1.1" name="org.springframework.spring">
<resources>
<resource-root path="spring-aop-3.2.3.RELEASE.jar"/>
<resource-root path="spring-beans-3.2.3.RELEASE.jar"/>
<resource-root path="spring-context-3.2.3.RELEASE.jar"/>
<resource-root path="spring-core-3.2.3.RELEASE.jar"/>
<resource-root path="spring-expression-3.2.3.RELEASE.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="org.apache.commons.logging"/>
</dependencies>
</module>
5.Put the following jboss-deployment-structure.xml in your application archive (WEB-INF/jboss-deployment-structure.xml for WAR or META-INF/jboss-deployment-structure.xml for EAR or EJB-jar) to use the above module:
If you're using JBoss EAP 6.1.x and greater or EAP 7, then use below:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.springframework.spring" export="true" meta-inf="export"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
If JBoss EAP 6.0.x, then use below
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.springframework.spring" export="true">
<imports>
<include path="META-INF**"/>
<include path="org**"/>
</imports>
<exports>
<include path="META-INF**"/>
<include path="org**"/>
</exports>
</module>
</dependencies>
</deployment>
</jboss-deployment-structure>
Note: The meta-inf on the module in the jboss-deployment-structure.xml was added in JBoss EAP 6.1.0, which allows the files in the META-INF of a resource to be visible. Since this was not available in JBoss EAP 6.0.x, the section allows you to get access to the META-INF directory which is not visible by default.
Note: The Spring Framework module should not include resources such as servlet-api.jar, xml-apis.jar, jta-api.jar, and other APIs. These APIs are implemented by either the JDK or JBoss and trying to use a different version of the API will lead to classloading issues and other problems.
Note: The Spring module should include all of its non Java / JavaEE dependencies. The Spring module can depend on javax.api / javaee.api provided by JBoss and any public JBoss module, but for other dependencies Spring has such as aopalliance, they would need to be included as resources in the module or in another custom module.

deploy WMQ resource adapter as a module in JBoss EAP 6

I'm trying to simplify the provisioning of JBoss EAP 6 applications by adding common components to the base EAP 6 installation directory (e.g. ojdbc driver).
For the WMQ JCA resource adapter, I have everything working just fine if I put the 'wmq.jmsra.rar' archive in the 'deployments' folder. I just need to configure the resource-adapters section of the standalone.xml file according to the official documentation.
Now, is it possible to create a JBoss module and include it via the 'global-modules' section? I tried creating a module wmq.ra with resource-root wmq.jmsra.rar, but the module won't load.
I may have found the answer i was looking for. I ran into post about the similar issue for Active MQ here and here. I followed the same canvas for WMQ:
unpack the wmq.jmsra.rar in your module directory (e.g. modules/wmq/jmsra/main/)
create a module.xml descriptor for you module
this one worked for me with WMQ 7.5.0.3. I had problems when some of the dependencies were missing
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="wmq.jmsra">
<resources>
<resource-root path="."/>
<resource-root path="com.ibm.mq.commonservices.jar"/>
<resource-root path="com.ibm.mq.connector.jar"/>
<resource-root path="com.ibm.mq.headers.jar"/>
<resource-root path="com.ibm.mq.jar"/>
<resource-root path="com.ibm.mq.jmqi.jar"/>
<resource-root path="com.ibm.mq.jmqi.local.jar"/>
<resource-root path="com.ibm.mq.jmqi.remote.jar"/>
<resource-root path="com.ibm.mq.jmqi.system.jar"/>
<resource-root path="com.ibm.mq.jms.admin.jar"/>
<resource-root path="com.ibm.mq.pcf.jar"/>
<resource-root path="com.ibm.mqjms.jar"/>
<resource-root path="com.ibm.msg.client.commonservices.j2se.jar"/>
<resource-root path="com.ibm.msg.client.commonservices.jar"/>
<resource-root path="com.ibm.msg.client.jms.internal.jar"/>
<resource-root path="com.ibm.msg.client.jms.jar"/>
<resource-root path="com.ibm.msg.client.matchspace.jar"/>
<resource-root path="com.ibm.msg.client.provider.jar"/>
<resource-root path="com.ibm.msg.client.ref.jar"/>
<resource-root path="com.ibm.msg.client.wmq.common.jar"/>
<resource-root path="com.ibm.msg.client.wmq.factories.jar"/>
<resource-root path="com.ibm.msg.client.wmq.jar"/>
<resource-root path="com.ibm.msg.client.wmq.v6.jar"/>
<resource-root path="dhbcore.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.resource.api"/>
<module name="javax.jms.api"/>
<module name="javax.management.j2ee.api"/>
</dependencies>
</module>
import your module the usual way in standalone.xml
I didn't fully validate this solution in production like environment, I'll update if needed.
You can refer to EAP6 and WebSphere MQ Integration document for installing and configuring the resource adapter.

JBoss AS 7.1.1 Final and Log4j-extras

I want to add log4j-extras jar in my jboss server but i don't know how to do this correctly.
I put apache-log4j-extras-1.2.17.jar into jboss_HOME/modules\org\apache\log4j\main (same location as log4j-1.2.16.jar) and my module.xml looks like :
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.apache.log4j">
<properties>
<property name="jboss.api" value="private"/>
</properties>
<resources>
<resource-root path="log4j-1.2.16.jar"/>
<!-- Insert resources here -->
<resource-root path="apache-log4j-extras-1.2.17.jar"/>
</resources>
<dependencies>
<module name="org.dom4j" optional="true"/>
<module name="javax.api"/>
<module name="org.jboss.logmanager"/>
<module name="org.jboss.modules"/>
</dependencies>
</module>
After start jboss, i have new files in the directory :
apache-log4j-extras-1.2.17.jar.index and log4j-1.2.16.jar.index
I have an application which use an external log4j.properties.
The configuration is ok but when i try to add "log4j.appender.test=org.apache.log4j.rolling.RollingFileAppender", i have the error message "log4j:ERROR Could not instantiate class [org.apache.log4j.rolling.RollingFileAppender]"
So i guess that the add of log4j-extras is not ok.
Can someone tell me the correct configuration to do in jboss ? (maybe the module.xml is not correct or i need to create an other directory in module ?)
Thanks a lot !

Path setting for DLL's in JBOSS 7.1.1

We have some DLL's which are related to Java,VB. In Joss 4.X , We used to place in bin directory under Application Server.
We migrated to JBOSS 7.1.1 and when I removed from bin directory and placed them in libraries folder under C:\jboss-as-7.1.1.Final\modules\com\correction\main\libraries .
I am getting this exception
java.lang.UnsatisfiedLinkError: no xxxJavaWrapper in java.library.path
java.library.path = C:\Program Files\Java\jdk1.6.0_24\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\apache-maven-3.0.4;C:\apache-maven-3.0.4\bin;C:\Python27;C:\Program Files\Java\jdk1.6.0_24;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
java.lang.UnsatisfiedLinkError: com.xxxJavaWrapperJNI.new_xxx()J
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.correction">
<resources>
<resource-root path="xxx.jar"/>
<resource-root path="xyz.jar"/>
<resource-root path="libraries"/>
</resources>
<dependencies>
<system export="true">
<paths>
<path name="libraries"/>
</paths>
<exports>
<include-set>
<path name="libraries"/>
</include-set>
</exports>
</system>
</dependencies>
</module>
But I place the same dll's in bin folder, it is working fine.
I want to place them in module folder and set the path from there instead of bin so that I can have all the application related jar's, properties and dll files at one place for ease maintainance.
Also I want to know how to set the path of txt and properties files in jboss 7.1.1
Regards
Srini
Configure module.xml as below:
<module xmlns="urn:jboss:module:1.1" name="com.correction">
<resources>
<resource-root path="xxx.jar"/>
<resource-root path="xyz.jar"/>
<resource-root path="lib/win-x86_64"/>
</resources>
<dependencies>
<module name="sun.jdk"/>
</dependencies>
</module>
Put the DLLs into the directory lib/win-x86_64. Check the another dependencies of your project.
In WEB-INF of your application creating the file jboss-deployment-structure.xml and put the content below:
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.correction"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
That's all.
Another Question: How can you make these properties files accessible to applications deployed on JBoss 7?
create a custom module where you put your properties files and put jboss-deployment-structure.xml to your application archive (WAR/EAR) to use that custom module.
Create the new module directory under $JBOSS_HOME/modules(using app/conf in this example)
mkdir -p $JBOSS_HOME/modules/app/conf/main/properties/
Put your properties files in $JBOSS_HOME/modules/app/conf/main/properties/
Create a module.xmlhere $JBOSS_HOME/modules/app/conf/main/module.xml
<module xmlns="urn:jboss:module:1.1" name="app.conf">
<resources>
<resource-root path="properties"/>
</resources>
</module>
put the following jboss-deployment-structure.xml in WEB-INF:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="app.conf" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Then you can access your properties files using thecode below (example assumes you have a
example.propertiesfile in $JBOSS_HOME/modules/app/conf/main/properties/)
Thread.currentThread().getContextClassLoader().getResource("example.properties");
Ps: I used JBoss AS 7.1.2 ( JBoss EAP 6 )
Regards
Mauricio Magnani