Maven create WAR file from pom.xml - Java @ Desk

Tuesday, January 20, 2015

Maven create WAR file from pom.xml

Maven create WAR file from pom.xml

To create a WAR file directly from pom.xml and place it to external directory. The external directory can be a server location where the war needs to be deployed.

To achieve so, maven-war-plugin is used in the pom.xml to configure a war packaging at the external location as shown below:
1) Create Maven WebApp project in Eclipse, i.e. MavenSampleProjArtifactId
2) Add maven-war-plugin to pom.xml file
3) Run command clean install to generate .war file

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-war-plugin</artifactId>
 <configuration>
  <warName>MavenSampleProjArtifactId</warName>
  <outputDirectory>F:\Jboss\server\default\deploy</outputDirectory>
 </configuration>
</plugin>


On command run mvn install, the war file will be created at the location mentioned in tag

Console Output To check War File creation at location mentioned above

[INFO] --- maven-install-plugin:2.4:install (default-install) @ MavenSampleProjArtifactId ---
[INFO] Installing F:\Jboss\server\default\deploy\MavenSampleProjArtifactId.war







No comments:

Post a Comment