【发布时间】:2009-09-08 10:41:09
【问题描述】:
我已将我的程序集描述符配置为具有 jar 类型的程序集
<formats>
<format>jar</format>
</formats>
但是,在运行 mvn install 时获取的是 zip 文件而不是 jar。我哪里出错了?
【问题讨论】:
-
你可以发布你的程序集的其余部分吗?
标签: maven-2 maven-plugin
我已将我的程序集描述符配置为具有 jar 类型的程序集
<formats>
<format>jar</format>
</formats>
但是,在运行 mvn install 时获取的是 zip 文件而不是 jar。我哪里出错了?
【问题讨论】:
标签: maven-2 maven-plugin
此配置生成一个带有分类器 jar-assembly 的 jar 程序集,其中仅包含目标/类的内容。如果需要将其他内容添加到 jar 中,您可以添加其他文件集。为确保您的目标目录中没有任何先前运行的 zip 存档,您可以将其删除或运行 mvn clean。
<assembly>
<id>jar-assembly</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
插件配置应如下所示。注意将 appendAssemblyId 设置为 false 将导致默认 jar 被程序集中的 jar 替换,如果这不是所需的行为,请删除该元素:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/archive.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
【讨论】:
为什么不使用pre-defined assembly jar-with-dependencies?描述符文件下方:
<assembly>
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
</fileSet>
</fileSets>
</assembly>
要通过预定义的描述符使用assembly:assembly,请运行:
mvn assembly:assembly -DdescriptorId=jar-with-dependencies
要生成程序集作为正常构建周期的一部分,请将单个或单目录 mojo 绑定到包阶段(请参阅 Usage):
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- append to the packaging phase. -->
<goals>
<goal>single</goal> <!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
[...]
</project>
【讨论】: