1

I have a project which can be packaged and deployed two different ways, it's either a WAR for Tomcat, or a shaded JAR for AWS Lambda. Currently this isn't working very well, I have to keep changing the pom.xml back and forth when doing a release. Is there a way to accomplish this with Maven profiles?

e.g., I'd like to do

mvn install -Pwar 

to generate the WAR, and

mvn install -Plambda

to generate the shaded JAR.

Is this possible?

Alex R
  • 11,364
  • 15
  • 100
  • 180
  • 1
    Simply use the `profile -> plugins -> plugin -> executions -> execution` to define custom executions of the relevant plugins (I assume it will be `shade:shade` and `war:war` goals in your case). Bind them to the same phases they would normally be executed (see the doc of each plugin) .You can disable the default execution of the plugins as described here: https://stackoverflow.com/questions/14476757/disable-maven-plugins-when-using-a-specific-profile – crizzis Jul 11 '17 at 18:57

1 Answers1

3

You can try to include the following in your pom.xml

        <packaging>${packaging.type}</packaging> 

        <profiles>
            <profile>
                <id>lambda</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
                    <packaging.type>jar</packaging.type>
                </properties>
            </profile>
            <profile>
                <id>war</id>
                <properties>
                    <packaging.type>war</packaging.type>
                </properties>
                    </profile>
              </profiles>
fg78nc
  • 4,774
  • 3
  • 19
  • 32