How to deploy an application on Wildfly/JBoss EAP 7 via the Wildfly Maven Plugin


Octocat **Promotion** - Efficiently manage your coding bookmarks, aka #codingmarks, on www.codingmarks.org and share your hidden gems with the world. They are published weekly on Github. You can help us build THE programming-resources location - Star


This post shows how to deploy a Java EE application on a WildFly or JBoss EAP 7 via the WildFly Maven Plugin1. You can use this plugin to deploy, undeploy or run your application. The post has two parts:

  • deploy application on local server
  • deploy application on remote server via https

Deploy on local Wildfly

Place the plugin configuration in pom.xml file of the module you want to deploy to JBoss. It can be either a war or ear:

<project>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>1.1.0.Final</version>
                <configuration>
                    <hostname>localhost</hostname>
                    <port>9990</port>
                    <username>jboss-local-admin</username>
                    <password>jboss-local-admin-password</password>
                    <jboss-home>local-jboss-home</jboss-home>
                    <name>${project.build.finalName}.${project.packaging}</name>
                </configuration>
                <executions>
                    <!-- Undeploy the application on clean -->
                    <execution>
                        <id>undeploy</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>undeploy</goal>
                        </goals>
                        <configuration>
                            <ignoreMissingDeployment>true</ignoreMissingDeployment>
                        </configuration>
                    </execution>

                    <!-- Deploy the application on install -->
                    <execution>
                        <id>deploy</id>
                        <phase>install</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
        ...
    </build>
...
</project>

Note:

  • undeploy - is bound to the clean phase, and it won’t complain if it’s not present
  • deploy - is bound to the install phase
  • if you don’t want the deployment to happen in the installation phase, consider moving it in an upper phase in the the maven build cycle2 (e.g. deploy) or enclose it in a profile; for the latter see the second example below

Deploy on remote Wildfly

<profiles>
    <profile>
        <id>deployRemote</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>1.1.0.Final</version>
                    <configuration>
                        <hostname>remote_host</hostname>
                        <protocol>https-remoting</protocol>
                        <port>9993</port>
                        <username>jboss-admin</username>
                        <password>jboss-admin-password</password>
                        <jboss-home>remote-jboss-home</jboss-home>
                        <name>${project.build.finalName}.${project.packaging}</name>
                    </configuration>
                    <executions>
                        <!-- Undeploy the application on clean -->
                        <execution>
                            <id>undeploy</id>
                            <phase>clean</phase>
                            <goals>
                                <goal>undeploy</goal>
                            </goals>
                            <configuration>
                                <ignoreMissingDeployment>true</ignoreMissingDeployment>
                            </configuration>
                        </execution>

                        <!-- Deploy the application on install -->
                        <execution>
                            <id>deploy</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>deploy</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

Note:

  • undeploy - is bound to the clean phase, and it won’t complain if it’s not present
  • deploy - is bound now to the deploy phase
  • https is enabled by setting the protocol to https-remoting and the corresponding port 9993
  • the plugin’s operations are now executed only with a specified profile deployRemote; so you’d have to run the build like the following:
shell> mvn clean deploy -PdeployRemote

References

Adrian Matei

Adrian Matei
Life force expressing itself as a coding capable human being

New codingmarks published in week 48 of 2018

New codingmarks published in week 48 of 2018. Keywords: android, angular, api, documentation, feign, graphql, http, http-client, http2, https, java, kotlin, mapper, mapping, odata, rest, rest-client, spring, spring-boot and swagger Continue reading

New codingmarks published in week 46 of 2018

Published on November 20, 2018

New codingmarks published in week 45of 2018

Published on November 13, 2018