ThinWar with Widlfy

Create thin wars with wildfly. Ship dependencies with the application servers.

Albert Lacambra BasilAlbert Lacambra Basil

I have heard the concept of ThinWars several years before in one of the airhacks workshop from Adam Bien.

Basically, the idea is that in any project packaged into a war should contain only business logic. No jar dependencies should be packaged with the business code. That reduces drastically the size of the final war file, improving build, package, delivery and start-up times.

So, to be able to remove all dependencies from our war artifact, we need to change the scope from compiled to provided, and then add those dependencies directly to our application server. In a naive first approach, I have tried just to add those dependencies to the java classpath. However, the wildfly’s class loading is much more complex than that.

To add new dependencies into the Widlfly application server, we need to add them creating a new module. That means that we must create a new module.xml file, declaring included jars and dependencies.

So, to create a new module we must follow the next steps.

  • Create the module directory:

mkdir -p $JBOSS_HOME/modules/my/module/name/main
  • Create a module.xml file with including our depenedencies. Required jars can be directly downloaded form https://mvnrepository.com

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="my.module.name">
   <resources>
      <resource-root path="{my-dependency-jar1.jar}" />
      <resource-root path="{my-dependency-jar2.jar}" />
   </resources>
</module>
  • Declare the module as a global module into settings.xml so that it can be used by any deployed application. Under the <subsystem> section add:

<global-modules>
    <modulename="my.module.name"slot="main"/>
</global-modules>