我有一个项目(类型为“jar”)(显然)构建了一个 jar。但是那个项目有很多依赖项。我希望 Maven 构建一个“包”或“程序集”,其中包含我的 jar、所有依赖的 jar 和一些脚本(用于启动应用程序等)
解决此问题的最佳方法是什么?具体来说,让家属加入议会的最佳方式是什么?
最佳答案
对于单个模块,我会使用如下所示的程序集 (src/assembly/bin.xml
):
<assembly>
<id>bin</id>
<formats>
<format>tar.gz</format>
<format>tar.bz2</format>
<format>zip</format>
</formats>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>src/main/command</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*.sh</include>
<include>*.bat</include>
</includes>
</fileSet>
</fileSets>
</assembly>
要使用此程序集,请将以下配置添加到您的 pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/assembly/bin.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
在此示例中,启动/停止脚本位于 src/main/command
下并捆绑到 bin
中,依赖项捆绑到 lib
.自定义它以满足您的需求。
关于java - 使用 Maven,我如何构建一个包含项目 jar 和所有依赖 jar 的可分发文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1792763/