java – 如何使用Maven创建具有依赖项的可执行JAR?
作者:互联网
我想将我的项目打包在一个可执行的JAR中进行分发.
如何将所有依赖JAR的Maven项目打包到我的输出JAR中?
解决方法:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
你运行它
mvn clean compile assembly:single
应该在汇编之前添加编译目标:单个或者不包括您自己项目中的代码.
在评论中查看更多详情.
通常,此目标与构建阶段相关联,以自动执行.这可确保在执行mvn install或执行部署/发布时构建JAR.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
标签:java,maven-2,build-automation,build-process,executable-jar 来源: https://codeday.me/bug/20190910/1802073.html