Search code examples
javamavennetbeanspom.xml

Maven copy JAR generated in Target to external folder


In regular Netbeans project you have a build.xml where I am able to copy the generated JAR file to a different folder(s) using the following:

<target name ="-post-jar" > 
    <copy file ="${dist.jar}" todir ="../Plugin Jars" failonerror ="true"/> 

    <copy file ="${dist.jar}" todir ="/Users/dev/Desktop/plugins" failonerror ="true"/> 
</target>

Now that I have a project that uses Maven, I can't find the way to accomplish the same.

EDIT: Thanks to our contributors I was able to do it with the following entry

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.0.1</version>
        <executions>
          <execution>
            <id>copy-installed</id>
            <phase>install</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>${project.groupId}</groupId>
                  <artifactId>${project.artifactId}</artifactId>
                  <version>${project.version}</version>
                  <type>${project.packaging}</type>
                </artifactItem>
              </artifactItems>
              <outputDirectory>/Users/dev/Desktop/plugins</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

Solution

  • Use the maven-dependency-plugin

    The following documentation has an example where they copy the just built artifact to a custom location.

    https://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html (search the page for "The dependency:copy goal can also be used to copy the just built artifact to a custom location if desired")