我已将程序集描述符配置为具有jar类型
的程序集<formats>
<format>jar</format>
</formats>
然而,在运行mvn install获取zip文件而不是jar.Where我出错了?
答案 0 :(得分:2)
为什么不使用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>
答案 1 :(得分:2)
此配置生成一个jar程序集,其分类器jar-assembly
仅包含目标/类的内容。如果需要,您可以添加其他文件集以将其他内容添加到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>