maven deploy additional jar file

Joshua Swink picture Joshua Swink · Apr 16, 2009 · Viewed 25.6k times · Source

I have an artifact which is being built and deployed in a particular way (not as a jar file). In the course of deployment, a war file is built.

How can I configure the pom so that the artifact is also deployed as a jar file, to a different location?

Answer

MariuszS picture MariuszS · Mar 19, 2013

Maven deploy means deploy artifact to a Maven Repository, not an application server.

Configure additional JAR artifact like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <id>make-a-jar</id>
            <phase>compile</phase>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Attach this new artifact to your project:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>attach-artifacts</id>
            <phase>package</phase>
            <goals>
                <goal>attach-artifact</goal>
            </goals>
            <configuration>
                <artifacts>
                    <artifact>
                        <file>some file</file>
                        <type>jar</type>                           
                    </artifact>
                </artifacts>
            </configuration>
        </execution>
    </executions>
</plugin>