This is follow up based on this answer.
I have a structure that looks like
$ ls service/target/
classes lib maven-status
You can use maven-assembly-plugin
to do that task.
Create an assembly definition file in src/assembly/distribution.xml
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>distribution</id>
<formats>
<format>tar</format>
</formats>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
</file>
</files>
<fileSets>
<fileSet>
<directory>${project.build.directory}/lib</directory>
<outputDirectory>lib</outputDirectory>
</fileSet>
</fileSets>
</assembly>
In pom.xml
file, add plugin declare, execution phase and goal for it.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<descriptor>${project.basedir}/src/assembly/distribution.xml</descriptor>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
More format file or customize of maven-assembly-plugin
can be found here: https://maven.apache.org/plugins/maven-assembly-plugin/