I want to update my pom.xml so that when someone uses: mvn clean package, the generated jar file is copied to the current directory. I'm looking at the maven plugin copy-resources, but i'm not sure how to specify the current directory, is there an operating system agnostic way to do this? Would like it to also work on windows, if possible
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}</outputDirectory>
<resources>
<resource>
<directory>target/Test-0.0.1-SNAPSHOT.jar</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Thanks
If by current directory you mean ${project.basedir}
then yes you can do this easily. Just make sure you use ${build.finalName}.jar
as the file name part as it will properly get the main artifact of a project with <packaging>
set to jar
(the default).
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}</outputDirectory>
<resources>
<resource>
<!-- Get main artifact -->
<directory>target/${build.finalName}.jar</directory>
<!-- Don't filter binary files -->
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
If you wanted to do the current working directory instead you should be able to do it using ${user.dir}
as the outputDirectory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With