Maven: update context root in EAR

Introduction

When using Maven3 to build your enterprise application containing an war file, the war file’s context root is set as

<artifactId>-<version>

If you want to overwrite this root context, you can do this in the EAR’s pom.xml.

Plugin configuration

<plugins>
 ...
 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-ear-plugin</artifactId>
 <version>2.4.2</version>
 <configuration>
 ...
 <modules>
 <webModule>
 <groupId>groupId</groupId>
 <artifactId>artifactId</artifactId>
 <contextRoot>/<yourcontextroot></contextRoot>
 </webModule>
 </modules>
</configuration>
 </plugin>
 </plugins>

Usually you should find the values for <groupId> and <artifactId> already in the same pom in the dependency lists, as the WAR should be a dependency of the EAR.  As you do not specify the version of the WAR in the webmodule configuration it updates on its own whenever you change the dependency version of the WAR.

Leave a Reply