load class in war into global classpath (Wildfly)

2k views Asked by At

I want to deploy a war file to a Wildfly 10 server and expose a class to the global class path. I want to be able to use this class within other war files.

Do you know if this is possible at deploytime?

Best Regards Alex

1

There are 1 answers

0
siom On

Different war files in the deployments directory are separated by different class loaders. Hence, you cannot access from one war classes from another war.

If you need "global" functionality that is accessible by all deployments, you can add a new module. Adjust and invoke the following command:

./jboss-cli.sh -c --command="module add --name=<your-module> --resources=<path-to-file>/<your-jar>.jar --dependencies=<your-dependencies-comma-separated>"

This will create a new folder under $JBOSS_HOME\modules with a module.xml file next to your jar. For more information about adding modules look for example here.

Then add a dependency on this new module in your two war files, either by adding the module's name to the Class-Path entry in your MANIFEST.MF file or by supplying a dedicated jboss-deployment-structure.xml file (for more information see here).