WAR packaging

Adding WAR packaging is actually very simple process, slightly different for servler 2.5 and 3.0/3.1 compatible servers:

Servlet 2.5

Add to your project war/WEB-INF/web.xml file containing:

<?xml version="1.0" ?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        version="2.5">

  <display-name>Play! 2.x</display-name>

  <listener>
      <listener-class>play.core.server.servlet25.Play2Servlet</listener-class>
  </listener>

  <servlet>
    <servlet-name>play</servlet-name>
    <servlet-class>play.core.server.servlet25.Play2Servlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>play</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

</web-app>

Add dependency:

    <dependencies>
        ...
        <dependency>
            <groupId>com.github.play2war</groupId>
            <artifactId>play2-war-core-servlet25_2.10</artifactId>
            <!-- <version>1.2.1</version> for Play! 2.2.x -->
            <!-- <version>1.3-beta3</version> for Play! 2.3.x -->
            <version>1.4-beta1</version> <!-- for Play! 2.4.x -->
        </dependency>
    </dependencies>

Configure maven-war-plugin plugin:

    <build>
        ...
        <plugins>
            ....
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
                    <primaryArtifact>false</primaryArtifact>
                    <warSourceDirectory>${project.basedir}/war</warSourceDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>make-war</id>
                        <phase>package</phase>
                        <goals>
                            <goal>war</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

See working example project tested with Apache Tomcat 6.0.44, 7.0.67 and 8.0.30.

Servlet 3.0

Add dependency:

    <dependencies>
        ...
        <dependency>
            <groupId>com.github.play2war</groupId>
            <artifactId>play2-war-core-servlet30_2.10</artifactId>
            <!-- <version>1.2.1</version> for Play! 2.2.x -->
            <!-- <version>1.3-beta3</version> for Play! 2.3.x -->
            <version>1.4-beta1</version> <!-- for Play! 2.4.x -->
        </dependency>
    </dependencies>

Configure maven-war-plugin plugin:

    <build>
        ...
        <plugins>
            ....
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <primaryArtifact>false</primaryArtifact>
                    <warSourceDirectory>${project.basedir}/war</warSourceDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>make-war</id>
                        <phase>package</phase>
                        <goals>
                            <goal>war</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

See working example project tested with Apache Tomcat 7.0.67 and 8.0.30.

Servlet 3.1

Add dependency:

    <dependencies>
        ...
        <dependency>
            <groupId>com.github.play2war</groupId>
            <artifactId>play2-war-core-servlet31_2.10</artifactId>
            <!-- <version>1.3-beta3</version> for Play! 2.3.x -->
            <version>1.4-beta1</version> <!-- for Play! 2.4.x -->
        </dependency>
    </dependencies>

Configure maven-war-plugin plugin:

    <build>
        ...
        <plugins>
            ....
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <primaryArtifact>false</primaryArtifact>
                    <warSourceDirectory>${project.basedir}/war</warSourceDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>make-war</id>
                        <phase>package</phase>
                        <goals>
                            <goal>war</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

See working example project tested with Apache Tomcat 8.0.30.

Attaching WAR file to project build artifacts

If you want to install or deploy generated WAR file, you have to attach it to the project. Do it by adding:

    <build>
        ...
        <plugins>
            ....
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.9.1</version>
                <executions>
                    <execution>
                        <id>attach-war</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                             <artifacts>
                                 <artifact>
                                     <file>${project.build.directory}/${project.build.finalName}.war</file>
                                     <type>war</type>
                                 </artifact>
                             </artifacts>
                         </configuration>
                     </execution>
                </executions>
            </plugin>
        </plugins>
    </build>