JBOSS CLI adding module with optional dependency - deployment

I have a module.xml that looks like:
<module xmlns="urn:jboss:module:1.1" name="com.oracle">
<resources>
<resource-root path="ojdbc6.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
Using JBOSS-CLI one can do this:
./jboss-cli.sh -c --command="module add --name=com.oracle --resources=<path-to-file>/ojdbc6.jar --dependencies=javax.api,javax.transaction.api,javax.servlet.api"
to deploy the module. It is almost the same exact thing and the module.xml is generated; so I need not keep track of another xml.
But how can I get the 'optional="true"' from JBOSS-CLI?
Version: JBOSS-EAP 6.2.0. (would be great if I can find a solution that would work for either jboss 6.x EAP and wildfly 8x).

The CLI module command appears to only support simple dependencies.
You could work around it by supplying a pre-generated modules.xml file and specifying it in the CLI command using
--module-xml=filepath_to_modules.xml

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.

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.

Custom jndi object factory in wildfly 8 for CDI

I am trying to achieve injecting a jndi resource using CDI for wildfly 8.
For this purpose i want to use a custom jnidfactory as developed in https://github.com/juanlmelo/mongo-jndi-plugin/
The problem is due to my limited knowledge in wildfly, I don't know the following.
1) how to activate/attach this jndifactory in wildfly, ofcourse I can create an object while startup and assign a jndi name to it programmatically , but want to explore custom factory feature of wildfly
2) the best practice to set the uri property needed by the object factory, i assume using System.getProperty inside the factory should suffice , as the DB uri will be different for each installation
once this is achieved I am confident I can get it injected into my classes using cdi.
I have tried my best to look for similar post, but couldn't find any, if you think this is duplicate please point me to the correct one.
Thanks,
If you want add custom JNDI factory to wildfly using https://github.com/juanlmelo/mongo-jndi-plugin/ you need to do few things:
1) You need to change a little bit implementation of https://github.com/juanlmelo/mongo-jndi-plugin/blob/master/src/main/java/com/mongodb/jndi/MongoClientJNDIFactory.java
- line 38 change to:
String mongoURI = (String) environment.get(MONGO_CLIENT_URI);
and comment out or delete lines 39-49
2) then run command mvn clean package and create directory eg.:
wildfly-8.1.0.Final/modules/com/mongodb/jndi/main/
copy there mongo-jndi-plugin-1.0.jar and create there module.xml file with content:
<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="com.mongodb.jndi">
<resources>
<resource-root path="mongo-jndi-plugin-1.0.jar"/>
</resources>
<dependencies>
<module name="com.mongodb.driver"/>
<module name="javax.api"/>
</dependencies>
</module>
3) add mongo driver
-create directory: wildfly-8.1.0.Final/modules/com/mongodb/driver/main
-create there file: module.xml and place there:
<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="com.mongodb.driver">
<resources>
<resource-root path="mongo-java-driver-2.11.0.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
-add to this directory mongo-java-driver-2.11.0.jar library
4) add something like this
<subsystem xmlns="urn:jboss:domain:naming:2.0">
<bindings>
<object-factory name="java:global/MongoClient" module="com.mongodb.jndi" class="com.mongodb.jndi.MongoClientJNDIFactory">
<environment>
<property name="mongoClientURI" value="mongodb://username:password#yourdomain.com:27017,username:password#yourdomain.com:27017"/>
</environment>
</object-factory>
</bindings>
<remote-naming/>
</subsystem>
to your domain.xml or standalone.xml
voilĂ 
After this steps you can inject MongoClient into your classes using #Resource annotation (eg. #Resource(lookup = "java:global/MongoClient"

JBoss 7.1 development issues

I am new to JBoss 7.1 and trying to migrate our appplication to migrate from jboss 6.0 to jboss 7.1 but at development time it loads only few specific jars automatically which is different from jboss 6.0 which loads all the jars from lib folder.If i add them externally then at deployement time it conflicts with the already available jars in jboss 7.1 /module folder.
so please let me know how to configure the jboss 7.1 so that it loads all or specified its internal jars.
If you need to use your own jar for the deployed application, then you can exclude these using a jboss-deployment-structure.xml file in your WEB-INF directory. Here is an example that describes about the format of the xml file.
I too faced same issue. One best thing I did was removing conflicting jars in JBoss lib folder as your deployment ear would have those already.
JBoss As 7.1 & JSF1.2, 2.0
Following required steps...
You have manually configure some files
1.Create folder MySQL folder\main folder
jboss-as-7.1.1.Final\modules\com\mysql
2.MySQL folder\module folder\add-> module.xml file and MySQL connector file
Module.xml code:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.10-bin.jar"/>
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
3.Go to the JBoss-as-7.1.1.Final\modules\org\hibernate\main
open the module.xml file & add
<module name="com.mysql"/>
4.Go to the JBoss-as-7.1.1.Final\modules\org\jboss\as\weld\main
open the module.xml file & add
<module name="javax.faces.api" slot="1.2"/>
5.Go to the JBoss-as-7.1.1.Final\modules\org\jboss\weld\core\main
open the module.xml file & add
<module name="javax.faces.api" slot="1.2"/>

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