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

允我心安 提交于 2020-08-06 07:57:13

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/47759298/jboss-eap-7-how-to-exclude-implicit-modules-from-deployment-javax-jms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!