Maven wildfly deployment with multiple servers (standalone)

1.5k Views Asked by At

in my environment I have two wildfly server where I want to deploy with the wildfly-maven-plugin.

The servers differ in the name dev01 and dev02 but have the same port 9993 and username and password.

My understanding is that the wildfly-maven-plugin support only single server deployment.

If the problem are not big enough we use a module/submodule structure where the war file will be build in a submodule.

I'm using two profiles wildfly-deploy-dev01 and wildfly-deploy-dev02.

<profiles>
    <profile>
        <id>wildfly-deploy-dev01</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>install</phase>
                            <goals>
                                <goal>deploy</goal>
                            </goals>
                            <configuration>
                                <skip>true</skip>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

    <profile>
        <id>wildfly-deploy-dev02</id>
        <build>
        [...]
<profiles>

In the main module I skipped it.

In the war submodule:

    <profiles>
    <profile>
        <id>wildfly-deploy-dev01</id>
        <build>
            <finalName>${project.artifactId}-v1.0</finalName>
            <plugins>
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <configuration>
                        <skip>false</skip>
                        <id>wildfly-credentials<id>
                        <hostname>dev01.example.com</hostname>
                        <protocol>remote+https</protocol>
                        <port>9993</port>
                     </configuration>
                    <executions>
                        <execution>
                            <phase>install</phase>
                            <goals>
                                <goal>deploy</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
     <profile>
        <id>wildfly-deploy-dev01</id>
        <build>
          [same as above for hostname dev02.example.com]
 </profiles>

First I was thinking everthing works fine but then I found out that only the last server will be deployed.

mvn wildfly:deploy -P wildfly-deploy-dev01,wildfly-deploy-dev02

I played around by setting the configration after the execution tag without success. It looks that the second profile overwrite the first one.

Futher I hardcoded the finalname because the parsedVersion is not parsed.

<finalName>${project.artifactId}-v${parsedVersion.majorVersion}.${parsedVersion.minorVersion}</finalName>

At the moment I'm lost with Maven. Has anybody an idea how I can deploy with the plugin on two servers?

Thanks, Markus

Ways which I tried:

1

There are 1 best solutions below

0
On

You should be able to do this in a single profile with different executions. There shouldn't be a need to multiple profiles.

<profiles>
    <profile>
        <id>wildfly-deploy</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <configuration>
                        <skip>false</skip>
                        <id>wildfly-credentials<id>
                        <protocol>remote+https</protocol>
                        <port>9993</port>
                     </configuration>
                    <executions>
                        <execution>
                            <id>deploy-dev1</id>
                            <phase>install</phase>
                            <goals>
                                <goal>deploy</goal>
                            </goals>
                            <configuration>
                                <hostname>dev01.example.com</hostname>
                            </configuration>
                        </execution>
                        <execution>
                            <id>deploy-dev2</id>
                            <phase>install</phase>
                            <goals>
                                <goal>deploy</goal>
                            </goals>
                            <configuration>
                                <hostname>dev02.example.com</hostname>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
<profiles>

With this you'd just have to do mvn clean install -Pwildfly-deploy.