maven Jboss plugin example - unix1998/technical_notes GitHub Wiki

Maven has plugins for interacting with JBoss (now part of Red Hat's WildFly project). One commonly used plugin for deploying to JBoss/WildFly is the wildfly-maven-plugin. This plugin allows you to deploy JAR/WAR files to a remote JBoss/WildFly server and perform server management tasks like restarting the server.

Steps to Set Up pom.xml for JBoss/WildFly Deployment

  1. Add the wildfly-maven-plugin to your pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>my-app</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>2.0.1.Final</version>
                <configuration>
                    <hostname>remote-server-hostname</hostname>
                    <port>9990</port> <!-- Management port -->
                    <username>admin</username>
                    <password>admin-password</password>
                </configuration>
                <executions>
                    <execution>
                        <id>deploy</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>redeploy</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>redeploy</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>undeploy</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>undeploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Key Configuration Options:

  • hostname: The hostname or IP address of your remote JBoss/WildFly server.
  • port: The management port of the JBoss/WildFly server (default is 9990).
  • username and password: Credentials for accessing the management console.

Commands to Deploy and Manage Applications:

  • Deploy: Deploys the application to the remote server.
    mvn wildfly:deploy
  • Redeploy: Redeploys the application, which is useful if the application is already deployed.
    mvn wildfly:redeploy
  • Undeploy: Undeploys the application from the remote server.
    mvn wildfly:undeploy

Example pom.xml with Deployment Profiles:

You can also create Maven profiles to manage different environments (e.g., development, testing, production).

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>my-app</artifactId>
    <version>1.0-SNAPSHOT</version>

    <profiles>
        <profile>
            <id>dev</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <version>2.0.1.Final</version>
                        <configuration>
                            <hostname>dev-server-hostname</hostname>
                            <port>9990</port>
                            <username>dev-admin</username>
                            <password>dev-password</password>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>prod</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <version>2.0.1.Final</version>
                        <configuration>
                            <hostname>prod-server-hostname</hostname>
                            <port>9990</port>
                            <username>prod-admin</username>
                            <password>prod-password</password>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

Using Profiles:

To deploy using a specific profile, you can use the -P flag with Maven commands:

mvn clean package -Pdev wildfly:deploy

or

mvn clean package -Pprod wildfly:deploy

Conclusion:

By configuring the wildfly-maven-plugin in your pom.xml, you can easily deploy JAR/WAR files to a remote JBoss/WildFly server and manage server operations directly through Maven commands. This setup simplifies the deployment process and integrates it seamlessly into your Maven build lifecycle.

⚠️ **GitHub.com Fallback** ⚠️