0

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?

simon
  • 12,666
  • 26
  • 78
  • 113
  • Feasible to split your project into 2 modules? one jar and one war... or use a maven profile to change the packaging? – vikingsteve Jan 18 '16 at 11:05
  • 2
    I would like to avoid splitting the project. But using a profile sounds good, I was not aware that this is a possibility - thanks. Searching for this I found a good example here on SO: http://stackoverflow.com/questions/8247720/changing-packaging-based-on-active-profile-in-pom I'll try this out right away. – simon Jan 18 '16 at 11:13
  • No worries, glad it helped :) – vikingsteve Jan 18 '16 at 11:15
  • It worked. :) If you want to add your comment as an answer, I'll accept it. – simon Jan 18 '16 at 11:16
  • 1
    Perhaps we can just mark this question as a duplicate, are you happy with that? – vikingsteve Jan 18 '16 at 11:17
  • That's ok, no problem. – simon Jan 18 '16 at 12:07

0 Answers0