Path setting for DLL's in JBOSS 7.1.1 - jboss

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

Related

How to exclude the specific jar from global module in jboss?

I have a war file that contains, some jackson dependencies and then when I try to deploy it on jboss eap 7.3 server, war deployment fails
Due to, as different version of these jackson jar are included via global modules. That I cannot or remove from their.
So I create a jboss-deployment-structure.xml file and tried excluding specific jar's inside the global module's but it did not worked.
But I was successful in excluding the whole global modules that I don't want.
This is what I tried!!
<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deployment>
<exclusions>
<module name="fb_library" />
</exclusions>
</deployment>
</jboss-deployment-structure>
This above config works, but it excludes the whole global fb_library folder, But as I needed to exclude some specific jar so tried this and it gave error as wrong format for jboss-deployment-structure.xml
This gave error of wrong config as mentioned above
<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deployment>
<exclusions>
<resources>
<resource-root path="jackson-core-2.6.6.jar"/>
<resource-root path="jackson-annotations-2.6.0.jar"/>
<resource-root path="jackson-databind-2.6.6.jar"/>
<resource-root path="jackson-dataformat-cbor-2.6.6.jar"/>
</resources>
</exclusions>
</deployment>
</jboss-deployment-structure>
PS:- I have updated the question, as suggested by some members in chat, previously I was asking the wrong question. Apologies for that.
Again I tried this and not working
<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deployment>
<exclusions>
<module name="com.fasterxml.jackson.core" />
<module name="com.fasterxml.jackson.annotation" />
<module name="com.fasterxml.jackson.databind.module" />
<module name="com.fasterxml.jackson.jaxrs" />
<module name="com.fasterxml.jackson.jaxrs.json" />
<module name="com.fasterxml.jackson.module.jaxb" />
</exclusions>
</deployment>
</jboss-deployment-structure>
In jboss-deployment-structure, you are not allowed to add resources content (Jar files).
you need to specify the module name added by the dependency jar file itself here is an example :
here is a jackson jar that I want to exclude from jboss modules :
the module name is : com.fasterxml.jackson.core
and in the jboss-deployment-structure.xml it will be :
<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deployment>
<exclusions>
<module name="com.fasterxml.jackson.core" />
</exclusions>
</deployment>
</jboss-deployment-structure>
This answer solve my problems for com.fasterxml.jackson.dataformat.cbor
FYI
https://stackoverflow.com/a/37859612/14337508

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

loading shared native modules from ear file than from web apps in JBoss environment

There is a jar which loads native libraries .so files. This jar is available as a jboss module on the server. Native files can be loaded only once per classloader.
There are two war modules war1, war2 inside an ear1 file. if the module is configured as jboss module in both war1 & war2, I have no issues. But I am looking for an alternative where if i configure the jar which is loading the native library in the earfile/lib and the war refers from there, does that work. That particular class should load only once and shoudl be available in both the war files.
Solution:
We need to add sub-deployment section to the jboss deployment xml file inside ear/Meta-INF folder. That way the jboss module can be made available to all other submodules/war modules.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.aexp.sec.crypto" export="TRUE" />
</dependencies>
</deployment>
<sub-deployment name="crypto-war1-1.0-SNAPSHOT.war">
<dependencies>
<module name="com.aexp.sec.crypto" />
</dependencies>
</sub-deployment>
<sub-deployment name="crypto-war2-1.0-SNAPSHOT.war">
<dependencies>
<module name="com.aexp.sec.crypto" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
Note: For the Benefits of the future users, adding the solution of #Vamshidhar Cheburthy below,
We need to add sub-deployment section to the JBoss deployment XML file inside ear/Meta-INF folder. That way the JBoss module can be made available to all other submodules/war modules.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.aexp.sec.crypto" export="TRUE" />
</dependencies>
</deployment>
<sub-deployment name="crypto-war1-1.0-SNAPSHOT.war">
<dependencies>
<module name="com.aexp.sec.crypto" />
</dependencies>
</sub-deployment>
<sub-deployment name="crypto-war2-1.0-SNAPSHOT.war">
<dependencies>
<module name="com.aexp.sec.crypto" />
</dependencies>
</sub-deployment>

Why does my JBoss module throw a ClassCastException?

Hi StackOverflow Community,
I have a WAR which I have deployed to a JBoss Wildfly 8.2 instance. Also in Wildfly, I have created two modules:
a third party JMS JCA adapter module,
and a model module (model.jar) that contains message classes used to communicate between the JMS broker and the WAR
The WAR has a jboss-deployment-structure.xml that declares a dependency on the JCA module:
<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="com.thirdparty.mq.ra" slot="main"/>
<module name="com.company.model" slot="main">
</dependencies>
</deployment>
</jboss-deployment-structure>
The WAR has the model.jar file packaged in its WEB-INF/lib folder.
The JMS module has a dependency on the model module:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.thirdparty.mq.ra">
<resources>
<resource-root path="."/>
<resource-root path="thirdparty-jms-provider.jar"/>
...
<resource-root path="thirdparty-lib.jar"/>
</resources>
<dependencies>
<module name="com.company.model"/>
<module name="javax.api"/>
<module name="javax.jms.api"/>
<module name="javax.transaction.api"/>
<module name="javax.management.j2ee.api"/>
<module name="javax.resource.api"/>
<module name="org.jboss.invocation"/>
<module name="org.jboss.remote-naming" optional="true"/>
<module name="org.slf4j"/>
</dependencies>
</module>
When running, I get the following exception:
Caused by: java.lang.ClassCastException: com.company.model.web.dto.WebAuthenticationResponse cannot be cast to com.company.model.web.dto.WebAuthenticationResponse
I suspect it is a classloader issue. Is there some extra information I have to specify in the module.xml or jboss-deployment-structure.xml files?
Thanks for your help!
Assuming that your model.jar corresponds to your com.company.model module, your WAR classloader now sees the model classes twice, both from its own libraries in WEB-INF/lib and via the module dependency.
You should either import or embed a module/library, but not both.
By the way, importing a RAR module looks a bit suspicious. You should never depend on the implementation of a resource adapter. Maybe you can factor out an API module and import that.

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 !