I have a Maven project, which builds a WAR (a REST web service running on Tomcat). In pom.xml I have
<packaging>war</packaging>
Some classes are used in another, separate project. I build these classes using the maven-jar-plugin, which is configured followingly:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>models</finalName>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<includes>
<include>com/initech/middleware/application/conversion/*</include>
<include>com/initech/middleware/error/*</include>
<!-- other includes removed for example brevity -->
</includes>
<excludes>
<!-- removed for example brevity -->
</excludes>
</configuration>
<executions>
<execution>
<id>make-a-jar</id>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
Currently I create the JAR file by changing the "packaging" option in the pom.xml manually from "war" to "jar" and running
mvn install
which creates the JAR file and installs it in my local repository. However, I would like to do this without having to manually edit the pom.xml file each time before building the JAR file. I have tried using the option "-Dpackaging=jar", but this did not help.
Is it possible to create the JAR file as configured with the maven-jar-plugin just by running maven in the command line, and if yes, how?