Sometimes it is convenient to copy jar-files automatically after a build into several different directories, for example if you have different config files for local tests and for office test server, then you may want to copy these files into local test directory, internal office test server and public distribution directory.
This short part of pom.xml contains 2 different methods to build UBER-JAR and copying them into 3 different directories: localtest, officetest and public
<build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.6</version> <configuration> <archive> <manifest> <mainClass>tv.tmd.YourMainClass</mainClass> </manifest> <manifestEntries> <Class-Path>.</Class-Path> </manifestEntries> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <manifestEntries> <Main-Class>tv.tmd.YourMainClass</Main-Class> <Build-Number>2</Build-Number> </manifestEntries> </transformer> </transformers> </configuration> </execution> </executions> </plugin> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.8</version> <executions> <execution> <id>copy</id> <phase>package</phase> <configuration> <target> <echo>ANT TASK - copying files....</echo> <copy todir="${basedir}/distribution/localtest" overwrite="true" flatten="true"> <fileset dir="${basedir}" includes="*.bat" > <include name="*.bat" /> <include name="ReadME.*" /> <include name="target/*.jar" /> </fileset> </copy> <copy todir="${basedir}/distribution/officetest" overwrite="true" flatten="true"> <fileset dir="${basedir}" includes="*.bat" > <include name="*.bat" /> <include name="ReadME.*" /> <include name="target/*.jar" /> </fileset> </copy> <copy todir="${basedir}/distribution/public" overwrite="true" flatten="true"> <fileset dir="${basedir}" includes="*.bat" > <include name="*.bat" /> <include name="ReadME.*" /> <include name="target/*.jar" /> </fileset> </copy> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build>