Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jboss EAP 7 - How to exclude implicit modules from deployment (javax.jms)?

I didn't think I would end up here but after a lot of Google and StackOverflow searches here I'm.

This is my exact problem except that I can't afford to make code changes.

The WAR I'm trying to deploy includes a JMS library (i.e. javax.jms, which I cannot exclude form the WAR.) which is already loaded by Jboss EAP 7 by default. The path to jar is something like this jboss/modules/system/layers/base/javax/jms/api/ain/jboss-jms-api_2.0_spec-1.0.0.Final-redhat-1.jar. Because of this two different versions of the same classes loading I'm getting ClassCastException.

org.apache.activemq-ra.ActiveMQConnectionFactory cannot to be cast to javax.jms.ConnectionFactory

So, I want Jboss to NOT load javax.jms so that my application can use the JAR included with the WAR.

So, I was wondering if there was any way to exclude the module globally (for all WAR deployments).

Excluding it per deployment would work too. And I do realize it can be acheivd using jboss-deployment-structure.xml but I can't get it to work.

Here is what I tried:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure
        xmlns="urn:jboss:deployment-structure:1.2">
    <deployment>
        <exclude-subsystems>
            <subsystem name="javax" />
            <subsystem name="javax.jms" />
        </exclude-subsystems>
    </deployment>
</jboss-deployment-structure>

and

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure
    xmlns="urn:jboss:deployment-structure:1.2">
    <deployment>
        <exclusions>
            <module name="javax" />
            <module name="javax.jms" />
            <module name="javax.jms.api" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

I placed the file in WEB-INF directory. It didn't work. It still loaded the JMS class from modules folder of Jboss EAP. So, how do I correctly do this?

like image 238
Dilip Raj Baral Avatar asked Dec 11 '17 18:12

Dilip Raj Baral


3 Answers

The correct jboss-deployment-structure.xml is here:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
    <deployment>
        <exclude-subsystems>
            <subsystem name="messaging-activemq"></subsystem>
        </exclude-subsystems>
        <exclusions>
            <module name="javax.jms.api"></module>
        </exclusions>
    </deployment>
</jboss-deployment-structure>

This way you exclude both messaging subsystem and the JMS api.

like image 111
Tair Avatar answered Oct 17 '22 00:10

Tair


You should remove the JMS API JAR from your deployment. You can still keep the JMS implementation JAR in your deployment but that should probably end up in a RAR, preferably outside your deployment.

like image 33
Philippe Marschall Avatar answered Oct 17 '22 01:10

Philippe Marschall


This link has some things you could try.

Notably:

I think the problem is that activemq-all-5.4.2.jar contains javax.jms.*. Your deployment already gets this implicitly from the javaee.api module (see more information about implicity module dependencies here). I don't think it is appropriate for an application module/jar to package Java EE interfaces. You can try simply deleting the javax directory from activemq-all-5.4.2.jar or using a different set of ActiveMQ jars in your module to limit it to only what you need.

and/or altering your module.xml for ActiveMQ

<module xmlns="urn:jboss:module:1.0" name="activemq">  
    <resources>  
        <resource-root path="activemq-all-5.4.2.jar"/>  
    </resources>  
    <dependencies>  
        <module name="javax.api"/>  
    </dependencies>
</module>

There appears to be a method to embed ActiveMQ in Jboss as well, if you're interested. I won't pull out information from that article, as it doesn't answer the original question.

like image 27
dimwittedanimal Avatar answered Oct 17 '22 00:10

dimwittedanimal