Maven : Change Packaging Type Based on Profile

This page last changed on Mar 31, 2006 by Kees de Kooter

I wanted to be able to build two types of binaries from the same project: a war file for deploment in a web container and a jar for console operation. This is what I came up with. I created two profiles in my pom each defining a packaging.type property. This property is referenced in the packaging tag.

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    ..
    <packaging>${packaging.type}</packaging>

    <profiles>
        <profile>
            <id>webapp</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <packaging.type>war</packaging.type>
            </properties>
        </profile>
        <profile>
            <id>batch</id>
            <properties>
                <packaging.type>jar</packaging.type>
            </properties>
                </profile>
          </profiles>
</project>