While working on automatically deploying a maven artifact to a WildFly server using the WildFly Maven Plugin, I could not find a full working example on the corresponding webpage. It took quite some time, even if it is not much code. Below is everything you need to deploy a maven artifact to WildFly.
This is the pom.xml I use for deploying to a local WildFly server. The pom file below can also be used for a remote deploy, however. I am using WidFly 14 for the example provided below.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | <?xml version="1.0" encoding="UTF-8"?> <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.illucit</groupId>     <artifactId>wildfly-deploy</artifactId>     <version>1.0.0</version>     <packaging>pom</packaging>     <dependencies>         <dependency>             <groupId>com.illucit</groupId>             <artifactId>ArtifactIWantToDeploy</artifactId>             <type>ear</type>             <version>${artifact.version}</version>         </dependency>     </dependencies>     <build>         <plugins>             <plugin>                 <groupId>org.wildfly.plugins</groupId>                 <artifactId>wildfly-maven-plugin</artifactId>                 <version>2.0.0.Final</version>                 <configuration>                     <hostname>localhost</hostname>                     <port>8080</port>                     <id>deploy_server</id>                     <groupId>com.illucit</groupId>                     <artifactId>ArtifactIWantToDeploy</artifactId>                     <name>ArtifactIWantToDeploy.ear</name>                 </configuration>                 <executions>                     <execution>                         <phase>install</phase>                         <goals>                             <goal>deploy-artifact</goal>                         </goals>                     </execution>                 </executions>             </plugin>         </plugins>     </build>     <repositories>         <repository>             <id>illucit_artifactory</id>             <name>illucIT Artifatory</name>             <url>https://myartifactory.illucit.com</url>         </repository>     </repositories> </project> | 
In order for being able to deploy to WildFly, you first have to create a new Management user by executing add-user.bat or add-user.sh in the bin directory of WildFly.
After that you have to store those credentials and the credentials of your maven repository in the home directory of the current user under .m2/settings.xml. In my example the artifact I am deploying is hosted on a private repository….
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                       http://maven.apache.org/xsd/settings-1.0.0.xsd"> 	<servers> 		<server> 			<id>deploy_server</id> 			<username>wildfly_management_user</username> 			<password>xxx</password> 		</server> 		<server> 			<id>illucit_artifactory</id> 			<username>artifactory_user</username> 			<password>xxx</password> 		</server> 	</servers> </settings> | 
The ids in the settings.xml have to match the server you want to deploy to (deploy_server in my example) and the maven repository where the artifact is stored (illucit_artifactory in my example).
The pom.xml also contains a variable for the corresponding artifact version that you want to deploy ( ${artifact.version} ).
Please also replace the mentioned artifact ArtifactIWantToDeploy with your corresponding maven artifact in the example above.
After setting everything up this way, you can simply do a deploy by running the maven command below in the same directory as the pom.xml provided above.
| 1 | mvn wildfly:deploy-artifact -Dartifact.version="3.2.1" | 
I hope this full example can help someone save an hour or two…
If you have any question or comments, please leave a message below!
 
	