
WildFly is a free, open source & cross platform application server (formely known as Jboss AS or Jboss). It is written in java programming language & currently it is being maintained, developed by Redhat. It is one of the most popular application servers among Java EE programmers all around the world.
WildFly provides multiple ways to deploy your applications. In this post, we will deploy applications to WildFly using wildfly-maven-plugin. See my other posts to learn the other ways to do it.
- How to deploy applications to WildFly using jboss-cli
- Deploy applications to a remote WildFly server using jboss-cli
- Deploy applications to a remote WildFly Server using jboss-cli-client.jar
- Deploy applications to a remote WildFly server using curl
The wildfly-maven-plugin is used to deploy, redeploy, undeploy or run your application. You can also deploy or undeploy artifacts, such as JDBC drivers, and add or remove resources. There is also the ability to execute CLI commands.
Available Goals:
wildfly:add-resource
adds a resource.wildfly:deploy
deploys the application to the application server.wildfly:deploy-only
deploys the application to application server invoking no other goals by default.wildfly:deploy-artifact
deploys an arbitrary artifact to the server.wildfly:redeploy
redeploys the application.wildfly:redeploy-only
redeploys the application invoking no other goals by default.wildfly:undeploy
undeploys the application.wildfly:run
runs the application server and deploys your application.wildfly:start
starts the application server and leaves the process running. In most cases the shutdown goal be executed to ensure the server is shutdown.wildfly:shutdown
shuts down a running application server.wildfly:execute-commands
executes commands on the running server.
Each goal can be explicitly executed from the command line or specified in the execution portion of the plugin in the POM file.
In this post, we will deploy applications to WildFly using wildfly-maven-plugin. The plugin goals deploy, undeploy, and redeploy can be used to deploy, redeploy and undeploy applications to a WildFly.
The first step is to add the appropriate configuration to your plugin configuration in the POM.
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>1.2.2.Final</version> </plugin> ... </plugins> ... </build> ... </project>
Set the server configuration parameters as maven properties
<properties> <wildfly-home>/Users/shimul/wildfly-12.0.0.Final</wildfly-home> <wildfly-hostname>127.0.0.1</wildfly-hostname> <wildfly-port>9990</wildfly-port> <wildfly-username>admin</wildfly-username> <wildfly-password>secret</wildfly-password> </properties>
Add properties inside plugin configurations
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>1.2.2.Final</version> <configuration> <hostname>${wildfly-hostname}</hostname> <port>${wildfly-port}</port> <username>${wildfly-username}</username> <password>${wildfly-password}</password> </configuration> </plugin>
Now you will be able to deploy, undeploy, redeploy to WildFly using corresponding maven goals i.e. wildfly:deply
, wildfly:undeply
, wildfly:redeply
To work with both local and remote WildFly, create two profiles with server configuration parameters.
<profiles> <profile> <id>wildfly-remote</id> <properties> <wildfly-id>wildfly-remote</wildfly-id> <wildfly-hostname>192.168.1.100</wildfly-hostname> <wildfly-port>9990</wildfly-port> <wildfly-username>admin</wildfly-username> <wildfly-password>secret</wildfly-password> </properties> </profile> <profile> <id>wildfly-local</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <wildfly-id>wildfly-local</wildfly-id> <wildfly-home>/Users/shimul/wildfly-12.0.0.Final</wildfly-home> <wildfly-hostname>127.0.0.1</wildfly-hostname> <wildfly-port>9990</wildfly-port> <wildfly-username>admin</wildfly-username> <wildfly-password>secret</wildfly-password> </properties> </profile> </profiles>
Now you will be able to deploy, undeploy, redeploy to WildFly using corresponding maven goals with specified profile using “-P <profile_name>”.
To deploy on the local WildFly server run the following command:
wildfly:deploy -P wildfly-local
To deploy on the remote WildFly server run:
wildfly:deploy -P wildfly-remote
Running mvn wildfly:deploy
will deploy the application in local WildFly as we set the “wildfly-local” profile active by default.
Above solution works but it has a security issue as we are setting the server credentials in pom.xml
. While sharing your application codes, it breaches security. To fix this issue, set the profile configurations in maven’s settings.xml
(can normally be found at ~/.m2/
).
Another solution is to add new server definitions in <servers> section in ~/.m2/settings.xml
file
<servers> <server> <id>remote-wildfly</id> <username>admin</username> <password>secret</password> </server> <server> <id>local-wildfly</id> <username>admin</username> <password>secret</password> </server> </servers>
The host name and the port number still needs to be configured in pom.xml. And how does it knows which server credentials to use? For this, the server id needs to be added to the configuration. Change plugin configuration as:
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>1.2.2.Final</version> <configuration> <id>${wildfly-id}</id> <hostname>${wildfly-hostname}</hostname> <port>${wildfly-port}</port> </configuration> </plugin>
That’s it. No password in our pom.xml
. But you will still have some deployment specific details in the pom.xml
. If you want to completely remove deployment specific details from the pom.xml
, then change plugin configuration as:
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>1.2.2.Final</version> </plugin>
And also remove the profiles section added previously. While running maven goals, specify server id, hostname, port dynamically by adding some maven command line arguments:
mvn clean package wildfly:deploy -Dwildfly.id=wildfly-local -Dwildfly.hostname=127.0.0.1 -Dwildfly.port=9990
mvn clean package wildfly:deploy -Dwildfly.id=wildfly-remote -Dwildfly.hostname=192.168.1.100 -Dwildfly.port=9990
And you’re done! No deployment specific configurations inside your pom.xml
. That’s the clean programmer’s way 🙂
That’s all for now. We have learn how to deploy applications to WildFly server (both local and remote) using the wildfly maven plugin and walked through couple of approaches to make the configuration clean. Have your say in comment section and feel free to share. And you are welcome to do experiments with other maven goals of the wildfly maven plugin.