can I include dependent jar files directly in a jboss EAP 7.3 container?

Viewed 483

I am migrating a java ear application from weblogic to jboss. The application is an ear with the below maven dependency on antlr in the pom:

<dependency>
    <groupId>antlr</groupId>
    <artifactId>antlr</artifactId>
    <version>2.7.7</version>
    <scope>test</scope>
</dependency>

On localhost we use jetty so it gets included by the pom I guess due to the scope being test. In our test/production environments we deploy on Weblogic and I am trying to get it moved to jboss. The ear fails when deploying to jboss because weblogic includes this antlr jar automatically in the container and jboss does not. So for jboss build I have to comment out the scope line and include antlr directly in the ear file. I would like to not change the code and still have it work on both jboss and weblogic.

Is it possible to include the antlr dependency directly in jboss as a module or some other classpath setting?

2 Answers

Antlr is a base module so you can add it to your dependencies, jboss will make the module accessible to your application.

One way it so add the dependencies in the manifest of your jar file, in your maven build:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.1</version>
            <configuration>
                <archive>
                    <manifestEntries>
                        <Dependencies>org.antlr</Dependencies>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

Alternatively you can add a jboss-deployment-structure.xml file to your application and declare the dependency there.

I ended up adding a module in jboss_home/module/antlr/main/module.xml but I think jboss-deployment-structure.xml would also have worked. jboss-deployment-structure is good I guess if I want to control which deployment gets the file. I wanted to give it to all deployments by default so made sense to put in the domain config file instead.

I put this in module.xml and the antlr jar in the same folder.

<module xmlns="urn:jboss:module:1.1" name="antlr">
    <resources>
        <resource-root path="antlr-2.7.7.jar"/>
    </resources>
</module>

Then I added this in my domain.xml:

<subsystem xmlns="urn:jboss:domain:ee:4.0">
        ...
        <global-modules>
             <module name="antlr" slot="main"/>
         </global-modules>
         ...
</subsystem>

I restarted all the hosts and deploy seems to work fine now. Thanks!

Related