您可以使用
Maven Assembly Plugin
.
首先,您需要向pom.xml中添加一些信息。
插件
使结果JAR可执行的部分:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.example.installer.Installer</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
我建议使用单独的
assembly descriptor
构建实际的安装程序jar。下面是一个例子:
<assembly>
<id>installer</id>
<formats>
<format>jar</format>
</formats>
<baseDirectory></baseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<includes>
<!-- this references your installer sub-project -->
<include>com.example:installer</include>
</includes>
<!-- must be unpacked inside the installer jar so it can be executed -->
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
<dependencySet>
<outputDirectory>/</outputDirectory>
<includes>
<!-- this references your server.war and any other dependencies -->
<include>com.example:server</include>
</includes>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
如果已将程序集描述符保存为“installer.xml”,则可以通过如下运行程序集来构建JAR:
MVN清理包程序集:single-ddescriptor=installer.xml
希望这有帮助。以下是一些您可能会发现有用的附加链接: