Friday, 3 May 2019

JBoss | How to exclude the JBoss javax.mail.api* API classes from a deployment in JBoss EAP 6?

JBoss EAP 6.x

1. Excluding javax.mail.api does not work
2. Trying to deploy an existing Spring application to JBoss and the deployed application's SMTP mail sending functionality is broken. User realized that JBoss is loading the javax.mail.api from its own (red-hat implementation of the jar) existing modules. The user wants to load its implementation.
3. User has been created a jboss-deployment-structure.xml and tried different exclusion ideas. However, none of them worked. JBoss Application Server refused to load our war provided javax.mail.jar.

User would need to exclude the javaee.api as it is an automatic dependency and exports javax.mail.api.

Hence the user would need to add all dependencies of javaee.api in jboss-deployment-structure.xml and exclude the default dependencies of javax.mail.api.

<xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1"
                  <module name="javaee.api" />
                  <module name="javax.mail.api" />
                  <module name="javax.activation.api" export="true" />
                  <module name="javax.annotation.api" export="true" />
                  <module name="javax.ejb.api" export="true" />
                  <module name="javax.el.api" export="true" />
                  <module name="javax.enterprise.api" export="true" />
                  <module name="javax.enterprise.deploy.api" export="true" />
                  <module name="javax.inject.api" export="true" />
                  <module name="javax.interceptor.api" export="true" />
                  <module name="javax.jms.api" export="true" />
                  <module name="javax.jws.api" export="true" />
                  <module name="" export="true" />
                  <module name="javax.persistence.api" export="true" />
                  <module name="javax.resource.api" export="true" />
                  <module name="javax.rmi.api" export="true" />
                  <module name="" export="true" />
                  <module name="" export="true" />
                  <module name="javax.servlet.api" export="true" />
                  <module name="javax.servlet.jsp.api" export="true" />
                  <module name="javax.transaction.api" export="true" />
                  <module name="javax.validation.api" export="true" />
                  <module name="" export="true" services="export" />
                  <module name="javax.xml.bind.api" export="true" />
                  <module name="javax.xml.registry.api" export="true" />
                  <module name="javax.xml.soap.api" export="true" />
                  <module name="" export="true" />

                  <!— OR can comment out to load from EAR -->
                  <module name="javax.mail.api" slot="1.4" />

                  <module name="javax.api" export="true" />


Define Custom module:
It is possible to create a custom module under $JBOSS_HOME/modules/ with a different version of a mail jar and then make application depend on it using the jboss-deployment-structure.xml. If you create a module, you should declare the dependencies below which are needed by the javax.mail.api classes.

<module xmlns="urn:jboss:module:1.3" name="javax.mail.api" slot="1.4">
            <module name="javax.activation.api" />
            <module name="javax.api" />

            <resource-root path="mail-1.6.jar" />

Related Posts Plugin for WordPress, Blogger...