NathanChristie
NathanChristie

Reputation: 2400

Can I force Maven to build a JAR even though POM packaging specifies WAR?

I'd like to build our project from the command line as a JAR without modifying the POM, which has the <packaging>war</packaging> configuration.

Is there a way to do this?

Upvotes: 2

Views: 1839

Answers (2)

NathanChristie
NathanChristie

Reputation: 2400

I was not able to explicitly build a jar while preventing the building of a war as well. But I realized I didn't have to. With this configuration of the maven-assembly-plugin, and the packaging set to WAR in my POM, a fat-jar and a war will always be created.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.5.3</version>
    <configuration>
        <finalName>myApp</finalName>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <archive>
            <manifest>
                <mainClass>com.company.app.Startup</mainClass>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

If this questions / answer seems confusing / not useful to searchers, feel free to delete it. Thanks to everyone who helped me get here.

Upvotes: 1

Matthias
Matthias

Reputation: 3556

If you are free to chose how maven is executed it is possible to call maven to invoke the jar goal directly:

mvn jar:jar

Upvotes: 3

Related Questions