How to create a .war file of a Mule Maven application

Home > Search > How-to


Before deploying a Maven .war file to Tomcat, ensure Tomcat can produce a simple XML file. For example, create a directory named testing, and add a file named web.xml.

[john.doe@server1 ~]# mkdir $TOMCAT_HOME/webapps/testing
[john.doe@server1 ~]# touch $TOMCAT_HOME/webapps/testing/web.xml


Add the following to the web.xml file. 

<?xml version="1.0" encoding="UTF-8"?>
<body>Hello XML!</body>


Navigate to http://localhost:8080/testing/web.xml, and the browser should display the literal XML.



Let's say your Maven project files are located at /etc/AnypointStudio/workspace/mymavenproject/. By default, your /etc/AnypointStudio/workspace/mymavenproject/pom.xml file will use mule packaging. Change the packaging to war.

  . . .
  . . .


If the /etc/AnypointStudio/workspace/mymavenproject/src/main/webapp/WEB-INF/web.xml does not exist, create it.

[john.doe@server1 ~]# mkdir /etc/AnypointStudio/workspace/mymavenproject/src/main/webapp
[john.doe@server1 ~]# mkdir /etc/AnypointStudio/workspace/mymavenproject/src/main/webapp/WEB-INF
[john.doe@server1 ~]# touch /etc/AnypointStudio/workspace/mymavenproject/src/main/webapp/WEB-INF/web.xml


Add the following to the web.xml file.



Add mvn to your PATH environment variable.

export PATH=$PATH:/etc/maven/apache-maven-3.5.0/bin/mvn


Move into the /etc/AnypointStudio/workspace/mymavenproject/ directory, and then package the application.

[john.doe@server1 ~]# mvn package


The build should be successful, and the .war file should be at /etc/AnypointStudio/workspace/mymavenproject/target/mymavenproject-1.0.0-SNAPSHOT.war.


The build will create a .war file at /etc/AnypointStudio/workspace/mymavenproject/target/mymavenproject-1.0.0-SNAPSHOT.war. Create a directory on Tomcat for your maven project, move into the directory, and extract the .war file.

[john.doe@server1 ~]# mkdir $TOMCAT_HOME/webapps/MyMavenProject
[john.doe@server1 ~]# cd $TOMCAT_HOME/webapps/MyMavenProject
[john.doe@server1 ~]# jar -xvf /etc/AnypointStudio/workspace/mymavenproject/target/mymavenproject-1.0.0-SNAPSHOT.war


In this example, /mymavenproject-1.0.0-SNAPSHOT is found in Tomcat.

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter in the box below so that we can be sure you are a human.