从单个 Maven 项目创建多个可运行的 Jars(包括依赖项) [英] Create multiple runnable Jars (with dependencies included) from a single Maven project
问题描述
我有一个包含多个主要类的 Maven 项目.我想从这些项目中生成可运行的 Jars(包括所有依赖项).我目前有以下构建配置(使用 maven.assembly):
I have a single maven project that has multiple main classes. I want to generate runnable Jars (that include all dependencies) out of these project. I currently have the following build configuration (using maven.assembly):
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>classpath.to.my.mainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
他们是通过 maven-assembly 实现这一目标的方法吗?如果不是,那么实现目标的最简单方法是什么?
Is their a way to achive this with maven-assembly? If not, what is the simplest way to achive my goal?
推荐答案
我无法用 maven-assembly-plugin
以令人满意的方式解决这个问题,所以我去找了一个不同的解决方案.我使用了 onejar-maven-plugin:
I wasn't able to solve this problem with the maven-assembly-plugin
in a satisfying way, so I went for a different solution. I used the onejar-maven-plugin:
<build>
<plugins>
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<id>build-first</id>
<configuration>
<mainClass>classpath.to.first.Main</mainClass>
<attachToBuild>true</attachToBuild>
<classifier>onejar</classifier>
<filename>first-runnable.jar</filename>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
<execution>
<id>build-second</id>
<configuration>
<mainClass>classpath.to.second.Main</mainClass>
<attachToBuild>true</attachToBuild>
<classifier>onejar</classifier>
<filename>second-runnable.jar</filename>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>onejar-maven-plugin.googlecode.com</id>
<url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
</pluginRepository>
</pluginRepositories>
这篇关于从单个 Maven 项目创建多个可运行的 Jars(包括依赖项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!