Bootstrap FreeKB - Mule - Create a .war file of a Mule Maven application
Mule - Create a .war file of a Mule Maven application

Updated:   |  Mule articles

XML

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.

 


Maven

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.

<project>
  . . .
  <packaging>war</packaging>
  . . .

 

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.

<plugin>            
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>        
  </configuration>
</plugin>

 

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.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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