问题
I have a task to copy a folder and create a jar. used maven-assembly plugin to generate a jar but the problem is its creates a Folder with artificat-id + Version i dont want to create i need as is what i copied and create a jar.
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>concordian</id>
<formats>
<format>jar</format>
</formats>
<!-- Adds the dependencies of our application -->
<fileSets>
<!-- Adds deploy scripts to the root directory of zip package. -->
<fileSet>
<directory>${project.build.directory}/concordion</directory>
<outputDirectory></outputDirectory>
<includes>
<include>**/**</include>
</includes>
</fileSet>
</fileSets>
</assembly>
it ends up in creating jar with folder + and whatever the file i copied from above structure. i need to remove the Folder +
回答1:
You can do it by different ways, with the maven-assembly-plugin
or with the maven-jar-plugin
:
- With the
maven-assembly-plugin
you have to declare the execution of the plugin in the pom and create your assembly file like this, you don't need to touch the configuration of themaven-jar-plugin
(except for other reasons) :
In the pom.xml :
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>jar-plus</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<skipAssembly>false</skipAssembly>
<descriptors>
<descriptor>src/assembly/jar-plus.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
Here I put the assembly in the folder src/assembly
, and I call it jar-plus.xml
.
Assembly jar-plus.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>jar-plus</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>${project.build.outputDirectory}</directory>
</fileSet>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>src/additionnal-folder</directory>
</fileSet>
</fileSets>
</assembly>
I put just one additionnal folder but you can configure as many as you want and set includes and excludes.
- With the
maven-jar-plugin
you have to make two executions of the plugin :
A first execution to generate the jar that will be the biggest one with all the resources defined with the maven-resources-plugin
. And a second execution for the smallest jar in which you will describe all the excludes in order to avoid the files you don't want to have in the smallest jar (I added classifiers in my sample code bellow to make the difference between the two jars but you can avoid adding a classifier for the "normal" jar).
In the pom.xml :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>biggest-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>biggest</classifier>
</configuration>
</execution>
<execution>
<id>normal-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>normal</classifier>
<excludes>
<exclude>**/*exclude-file*.*</exclude>
</excludes>
</configuration>
</execution>
</executions>
<configuration>
<includes>
<include>**/*.*</include>
</includes>
</configuration>
</plugin>
来源:https://stackoverflow.com/questions/28470153/copy-a-folder-and-create-a-jar-in-maven