使用Maven创建具有所有依赖项的zip [英] Create a zip with all dependencies with Maven
问题描述
Possible Duplicate:
With Maven, how can I build a distributable that has my project's jar and all of the dependent jars?
也许我是盲人,但是Maven程序集插件可以只创建一个包含当前project.jar和我所有依赖项jar的zip文件吗? "bin" ID仅包含我的project.jar,并且jar-with-dependencies将它们放到一个我不喜欢的jar中.
maybe I'm blind, but can the maven assembly plugin just create a zip file containing the current project.jar and all my dependency jars? the "bin" id contains just my project.jar and the jar-with-dependencies puts all together in one jar which I don't like.
推荐答案
您需要自定义程序集描述符才能执行所需的操作.它是bin和jar-with-dependencies预定义描述符的组合.在src/main/assembly
文件夹中创建了一个名为assembly.xml
的自定义程序集描述符.
You need a custom assembly descriptor to do what you want. It's a combination of the bin and the jar-with-dependencies predefined descriptors. Created a custom assembly descriptor called assembly.xml
in the src/main/assembly
folder.
下面是一个示例,该示例基本上是添加了依赖项集的bin描述符:
Here's an example that is basically the bin descriptor with the dependency set added:
<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>bin</id>
<formats>
<format>tar.gz</format>
<format>tar.bz2</format>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/site</directory>
<outputDirectory>docs</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
然后将pom更改为使用描述符而不是descriptorRef来告诉它自定义描述符在哪里.
Then change your pom to use a descriptor instead of a descriptorRef to tell it where your custom descriptor is.
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
[...]
</project>
这篇关于使用Maven创建具有所有依赖项的zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!