Main Tutorials

Maven – Deploy web application to WildFly

In Maven, we can use the official JBoss WildFly Maven Plugin to deploy a web application (war file) to the WildFly application server.

Technologies tested :

  1. Maven 3.3.9
  2. WildFly 9.0.2.final
  3. WildFly Maven Plugin 1.1.0.Alpha5

P.S This Spring MVC web application will be used for this deployment test.

1. Deploy WAR To WildFly

1.1 Start WildFly in standalone mode.


$ ./wildfly-9.0.2.Final/bin/standalone.sh 

=========================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: /home/mkyong/Desktop/wildfly-9.0.2.Final

  JAVA: /opt/jdk/jdk1.8.0_66/bin/java

... Http management interface listening on http://127.0.0.1:9990/management
... Admin console listening on http://127.0.0.1:9990
... WildFly Full 9.0.2.Final (WildFly Core 1.0.2.Final) started in 2260ms ...

1.2 Declares wildfly-maven-plugin in the pom.xml file.

pom.xml

  <plugin>
	<groupId>org.wildfly.plugins</groupId>
	<artifactId>wildfly-maven-plugin</artifactId>
	<version>1.1.0.Alpha5</version>			
  </plugin>

1.3 Deploy with mvn wildfly:deploy

WildFly Terminal

...
... WFLYUT0021: Registered web context: /spring4-mvc-maven-ajax-example-1.0-SNAPSHOT
... WFLYSRV0010: Deployed "spring4-mvc-maven-ajax-example-1.0-SNAPSHOT.war" 
(runtime-name : "spring4-mvc-maven-ajax-example-1.0-SNAPSHOT.war")

Access http://localhst:8080/spring4-mvc-maven-ajax-example-1.0-SNAPSHOT

1.4 Undeploy with mvn wildfly:undeploy

WildFly Terminal

...
... WFLYSRV0028: Stopped deployment spring4-mvc-maven-ajax-example-1.0-SNAPSHOT.war 
... (runtime-name: spring4-mvc-maven-ajax-example-1.0-SNAPSHOT.war) in 50ms
... WFLYDR0002: Content removed from location /home/mkyong/Desktop/wildfly-9.0.2.Final/
... standalone/data/content/94/c65382716f33f1c7e506208ed21616815438b2/content
... WFLYSRV0009: Undeployed "spring4-mvc-maven-ajax-example-1.0-SNAPSHOT.war" 
... (runtime-name: "spring4-mvc-maven-ajax-example-1.0-SNAPSHOT.war")

2. Update web context

By default, the filename of the war file (in target folder) will be registered as the web context. To custom it, define a deployment name by configure the name option like this :

pom.xml

  <plugin>
	<groupId>org.wildfly.plugins</groupId>
	<artifactId>wildfly-maven-plugin</artifactId>
	<version>1.1.0.Alpha5</version>	
	<configuration>
		<hostname>127.0.0.1</hostname>
		<port>9990</port>
		<username>mkyong</username>
		<password>password</password>
		<name>spring4ajax.war</name>
	</configuration>		
  </plugin>

In the above configuration, the spring4ajax will be the new web context path – http://localhst:8080/spring4ajax

Note
Remember to add the .war suffix, otherwise, NO web context will be registered!

References

  1. WildFly Maven Plugin
  2. Spring 4 MVC Ajax Hello World Example

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
5 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Utsav Patel
6 years ago

thanks for this article, i am able to deploy successfully but when i try to access it it says 404 not found.

Boris
2 years ago

It doesnt work(((
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project testserver: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]

Abin stephen
6 years ago

Is there any way to deploy to multiple instance of wildfly

Borgy Manotoy
7 years ago

Can this be used for production environment, if I have access the server’s terminal? lastly, is there any way to may it https ready? Thanks

Carol
8 years ago

Thanks for this article, very explanatory and easy to understand