How to place the output jar into another folder with maven?

Viewed 92185

I'd like to place my output jar and jar-with-dependencies into another folder (not in target/ but in ../libs/).

How can I do that?

6 Answers

I specially like the solution using maven-resources-plugin (see here) because is already included in maven, so no extra download is needed, and also is very configurable to do the copy at a specific phase of your project (see here to learn & understand about phases). And the best part of this approach is that it won't mess up any previous processes or build you had before :)

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>/dir/where/you/want/to/put/jar</outputDirectory>
              <resources>          
                <resource>
                  <directory>/dir/where/you/have/the/jar</directory>
                  <filtering>false</filtering>
                  <includes>
                     <include>file-you-want-to.jar</include>
                     <include>another-file-you-want-to.jar</include>
                  </includes>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

Of course you can also use interpolated variables like ${baseDir} and other good stuff like that all over your XML. And you could use wild cards as they explain here

Related