How to exclude the specific jar from global module in jboss? - 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

Related

Exclude static httpcomponent module without excuding resteasy from JBoss EAP 7.1

I need to exclude default httpcomponent module from my application, but I also use restasy and don't want to exclude or broke it. For httpcomponent I want to use versions from dependencies in my project. Is it possible with JBoss EAP 7.1?
Version of modules in jboss :
jackson-databind-2.8.9.redhat-1
jackson-core-2.8.9.redhat-1
jackson-annotations-2.8.9.redhat-1
I've tried to add to jboss-deployment-structure.xml this config but it didn't help:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.httpcomponents" />
<module name="org.jboss.resteasy.resteasy-jackson-provider" />
<module name="org.jboss.resteasy.resteasy-jackson2-provider" />
<module name="org.jboss.resteasy.resteasy-jettison-provider"/>
</exclusions>
<dependencies>
</dependencies>
</deployment>
</jboss-deployment-structure>
It should work, I can provide you a tested example (I've excluded the jettinson provider for my web app):
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<exclusions>
<module name="org.jboss.resteasy.resteasy-jettison-provider"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
I see only modules in your question, do you have the correct deployment -> exclusions structure?
If you need a list of JBoss EAP 7 modules, go here.

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>

Jboss configuration to load EAR jars for xerces and xalan

I have jars within my ear lib which need to be preferred over the application server similar jars like xalan, xerces etc. Weblogic allows this to done as below and the application works fine now in weblogic - with the configuration below
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.oracle.com/technology/weblogic/920/weblogic-application.xsd">
<xml>
<parser-factory>
<saxparser-factory> org.apache.xerces.jaxp.SAXParserFactoryImpl </saxparser-factory>
<document-builder-factory> org.apache.xerces.jaxp.DocumentBuilderFactoryImpl </document-builder-factory>
<transformer-factory> org.apache.xalan.processor.TransformerFactoryImpl </transformer-factory>
</parser-factory>
</xml>
<prefer-application-packages>
<package-name>org.opensaml.*</package-name>
<package-name>org.apache.xerces.*</package-name>
<package-name>org.apache.xalan.*</package-name>
</prefer-application-packages>
</weblogic-application>
I need to do the same with jboss so that it excluded the similar jars which are present within its own library. I have tried the below
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<ear-subdeployments-isolated>true</ear-subdeployments-isolated>
<deployment>
<dependencies>
<module name="deployment.javaee.api" />
</dependencies>
<exclusions>
<module name="javaee.api" />
</exclusions>
</deployment>
<module name="deployment.javaee.api">
<dependencies>
<module name="javaee.api" export="true">
<imports>
<exclude path="org/opensaml/**" />
<exclude path="org/apache/xerces/**" />
<exclude path="org/apache/xalan/**" />
</imports>
</module>
</dependencies>
</module>
</jboss-deployment-structure>
Still it seems to pick up the jboss jars for xerces , xalan and opensaml. In case you have done such things before in JBOSS, your suggestion will be really appreciated.

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.

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