我想创建一个多项目maven项目的单个可执行jar。这是我的项目结构,接下来是我试图用maven assembly插件做的事情。将会很感激任何人都可以暗示我的解决方案(这在我看来最为普遍,但在其他讨论链中找不到)。谢谢!多项目maven项目的单个可执行jar
我是(简体)的结构:
对myApp
…
<groupId>myApp</groupId> <artifactId>myApp</artifactId>
<version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging>
<name>myApp</name> <url>http://maven.apache.org</url>
…
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source> <target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>../m1</module> <!-- jar-->
<module>../m2</module> <!-- war -->
<module>../subAppPomAggregationProject</module>
</modules>
<dependencies>
…
</dependencies>
</project>
我想下面的插件添加到MyApp POM文件:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.mypath.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
当然事实并非如此为MyApp创建一个jar,但它确实在每个模块(!)中创建了一个似乎是聚集的jar的东西,尽管不是所有的依赖关系都是如此。
我也尝试创建另一个具有模块或MyApp依赖项的超级项目(jar) - 也没有工作。我是否应该在uber-jar中列出导入到MyApp的所有模块(以及导入到subAppPomAggregationProject中的模块)?没有尝试过,但如果是这样的话 - pom聚合器的目的是什么,为什么使用两阶段编译/汇总方法?
我无法尝试maven-shade-plugin(不知道它是否有帮助),因为它需要maven 3,我目前正在使用2.2.1(在我的近乎里程碑之前不想升级和晃动东西...)。
添加我这个插件在MyApp的pom.xml文件(POM包装),或做我创建另一个项目(比如说myappjar),我在其中放置插件?如果是后者,我只需将MyApp的依赖项放入myappjar pom.xml中? – Gera
每个模块一个工件。所以,不要劫持您的聚合器(也家长必须在孩子面前内置所以不能有这样即使你想) –
当我加入阴影插件MyApp的pom.xml中,我得到了以下错误:[INFO ]用阴影工件替换原始工件。 [INFO]用/home/.../MyApp/target/myapp-0.0.1-SNAPSHOT-shaded.pom取代null [错误]构建错误 [INFO]创建着色jar时出错:null。很明显,解决方案不起作用。将尝试第二个选项。 – Gera