道歉,如果在其他地方有所涉及,我恐怕无法找到这个特别琐碎问题的答案。
我有一个maven项目,它引用并构建了4个子项目(作为bundle)。我已经正确地设置了子项目之间的依赖关系,最终我得到了4个不同的.jar文件构建:
我的问题是,我如何设置mu父版本,以便当我从主.POM文件构建时,所有4个jar放在“/ parentproj / target /...”?
另一个问题是,如何构建xxxx-ALL.jar(合并这4个包的内容)?
答案 0 :(得分:3)
只需使用带有“dir”格式的Maven Assembly plugin将它们全部放在一个文件夹中,然后使用“jar”格式将它们分组到一个jar中。
更多细节:
pom.xml文件:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>distro-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<finalName>somefolder</finalName>
<attach>false</attach>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<phase>package</phase>
</configuration>
</execution>
</executions>
</plugin>
assembly.xml文件:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>SomeName</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<baseDirectory></baseDirectory>
<fileSets>
<fileSet>
<directory>appfiles</directory>
<includes>
<include>**</include>
</includes>
<outputDirectory>.</outputDirectory>
</fileSet>
</fileSets>
<moduleSets>
<moduleSet>
<!-- useAllReactorProjects must be false if the assembly's run on the project with the module list -->
<useAllReactorProjects>false</useAllReactorProjects>
<includeSubModules>false</includeSubModules>
<binaries>
<includeDependencies>true</includeDependencies>
<outputDirectory>bundle</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
答案 1 :(得分:1)
另一个问题是,如何构建xxxx-ALL.jar(合并这4个包的内容)?
您可以使用Maven shade plugin创建一个uber-jar(包含项目所有依赖项的jar)。只需创建另一个项目作为依赖项,并生成这个超级jar。