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

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

    <modulename="" slot="main"/>

Alternatively you can create a jboss-deployment-structure.xml file into the directories META-INF or WEB-INF

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
            <module name=""/>