How to add a custom module in Wildfly Swarm when executing from custom main()

691 Views Asked by At

I have a custom Wildfly module for logging in Json format, which my Swarm application references in standalone.xml:

<subsystem xmlns="urn:jboss:domain:logging:3.0">

    <console-handler name="CONSOLE">
        <level name="INFO" />
        <formatter>
            <named-formatter name="json-formatter" />
        </formatter>
    </console-handler>
    ...
    <formatter name="json-formatter">
        <custom-formatter module="my.package.jsonLogFormatter" class="my.package.jsonLogFormatter.JsonFormatter"/>
    </formatter>

</subsystem>

The module is saved in a Maven repository, from which it is copied during the Maven build to the target/classes folder.

The Maven wildfly-swarm-plugin then adds the module to the uberjar:

<plugin>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>wildfly-swarm-plugin</artifactId>
    <version>2017.7.0</version>
    <executions>
        <execution>
            <goals>
                <goal>package</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <additionalModules>
            <additionalModule>jsonLogFormatter-1.2</additionalModule>
        </additionalModules>
    </configuration>
</plugin>

This works as expected when executing from the uberjar.

However, when running a custom main() class directly from the IDE, there seems to be no way to tell Swarm to use this module:

public static void main(String... args) throws Exception {

    new org.wildfly.swarm.Swarm()
         //.customModule("path/to/module") // <- doesn't exist
         .start()
         .deploy();
}

Swarm shows this error during startup:

Failed to load module "my.package.jsonLogFormatter" for formatter "json-formatter"
0

There are 0 best solutions below