Java 在多模块maven项目中创建程序集存档时出错
我已经创建了一个包含两个模块(child1,child2)的多模块maven项目。Java 在多模块maven项目中创建程序集存档时出错,java,maven,maven-assembly-plugin,maven-module,Java,Maven,Maven Assembly Plugin,Maven Module,我已经创建了一个包含两个模块(child1,child2)的多模块maven项目。我正在尝试使用汇编插件创建一个包-APP.zip,其中应该包含APP.properties、child1.war和child2.war。但是当我运行mvn assembly:single命令时,我遇到了以下错误 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single (default-cli)
我正在尝试使用汇编插件创建一个包-APP.zip,其中应该包含APP.properties、child1.war和child2.war。
但是当我运行mvn assembly:single命令时,我遇到了以下错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single (default-cli) on project app: Failed to create assembly: Error creating assembly archive My_Package: You must set at least one file. -> [Help 1]
项目文件夹结构
app
|
pom.xml
assembly.xml
app.properties
child 1
|
pom.xml src target
|
child1.war
child 2
|
pom.xml src target
|
child2.war
父pom(app/pom.xml)
com.karthik
父母亲
聚甲醛
1.0-快照
父母亲
儿童1
儿童2
org.apache.maven.plugins
maven汇编插件
应用程序
错误的
assembly.xml
捆扎
仅有一个的
包裹
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">
<formats>
<format>zip</format>
</formats>
<id>My_Package</id>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.karthik:child1</include>
<include>com.karthik:child2</include>
</includes>
</moduleSet>
</moduleSets>
</assembly>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>../Child1/target/child1.war</source>
</file>
<file>
<source>../Child2/target/child2.war</source>
</file>
<file>
<source>../app.properties</source>
</file>
</files>
</assembly>
拉链
我的包
错误的
符合事实的
com.karthik:child1
com.karthik:child2
我相信我在程序集描述符中遗漏了导致此错误的内容。1) 您能否帮助解决此问题并帮助创建包含APP.properties、child1.war和child2.war的zip(APP.zip)?
2) 我们什么时候需要使用
&
标记?使用示例
这是一个工作示例,父pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.greg</groupId>
<artifactId>assembly-example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>assembly-example</name>
<modules>
<module>child1</module>
<module>child2</module>
<module>distribution</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
举个例子
这是一个工作示例,父pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.greg</groupId>
<artifactId>assembly-example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>assembly-example</name>
<modules>
<module>child1</module>
<module>child2</module>
<module>distribution</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
最后我找到了解决办法 1) 为父POM中的组件添加单独的模块-分发版。
母体聚甲醛
<project>
<groupId>com.karthik</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>parent</name>
<modules>
<module>child 1</module>
<module>child 2</module>
<module>distribution</module>
</modules>
</project>
com.karthik
父母亲
聚甲醛
1.0-快照
父母亲
儿童1
儿童2
分配
2) 在分发模块中配置maven程序集插件
分配模块POM
<parent>
<groupId>com.karthik</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>distribution</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Distribution</name>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-bundles</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
com.karthik
父母亲
1.0-快照
分配
聚甲醛
1.0-快照
分配
maven汇编插件
捆扎
仅有一个的
包裹
assembly.xml
3) 在组装描述符的
元素中添加要组装的文件/工件
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">
<formats>
<format>zip</format>
</formats>
<id>My_Package</id>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.karthik:child1</include>
<include>com.karthik:child2</include>
</includes>
</moduleSet>
</moduleSets>
</assembly>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>../Child1/target/child1.war</source>
</file>
<file>
<source>../Child2/target/child2.war</source>
</file>
<file>
<source>../app.properties</source>
</file>
</files>
</assembly>
分配
拉链
../Child1/target/Child1.war
../Child2/target/Child2.war
../app.properties
我终于找到了解决办法
1) 为父POM中的组件添加单独的模块-分发版。母体聚甲醛
<project>
<groupId>com.karthik</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>parent</name>
<modules>
<module>child 1</module>
<module>child 2</module>
<module>distribution</module>
</modules>
</project>
com.karthik
父母亲
聚甲醛
1.0-快照
父母亲
儿童1
儿童2
分配
2) 在分发模块中配置maven程序集插件
分配模块POM
<parent>
<groupId>com.karthik</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>distribution</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Distribution</name>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-bundles</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
com.karthik
父母亲
1.0-快照
分配
聚甲醛
1.0-快照
分配
maven汇编插件
捆扎
仅有一个的
包裹
assembly.xml
3) 在组装描述符的
元素中添加要组装的文件/工件
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">
<formats>
<format>zip</format>
</formats>
<id>My_Package</id>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.karthik:child1</include>
<include>com.karthik:child2</include>
</includes>
</moduleSet>
</moduleSets>
</assembly>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>../Child1/target/child1.war</source>
</file>
<file>
<source>../Child2/target/child2.war</source>
</file>
<file>
<source>../app.properties</source>
</file>
</files>
</assembly>
分配
拉链
../Child1/target/Child1.war
../Child2/target/Child2.war
../app.properties
在这里,你也可以得到你的战争和罐子,如你所愿。
像这样:
<outputFileNameMapping>${module.artifactId}.${module.extension}</outputFileNameMapping>
${module.artifactId}.${module.extension}
使用它获取war和jar文件
在汇编文件中:
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.greg:child1</include>
</includes>
<binaries>
<outputDirectory>modules/maven-assembly-plugin</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
符合事实的
com.greg:child1
模块/maven汇编插件
错误的
在这里,只需添加上面的一行即可获取jar文件,如下所示:
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.greg:child1</include>
</includes>
<binaries>
<outputDirectory>modules/maven-assembly-plugin</outputDirectory>
<outputFileNameMapping>${module.artifactId}.${module.extension}</outputFileNameMapping>
<unpack>false</unpack>
</binaries>
</moduleSet>
符合事实的
com.greg:child1
模块/maven汇编插件
${module.artifactId}.${module.extension}
错误的
希望这能帮助其他人
参考:
在这里,你也可以得到你的战争和罐子,如你所愿。
像这样:
<outputFileNameMapping>${module.artifactId}.${module.extension}</outputFileNameMapping>
${module.artifactId}.${module.extension}
使用它获取war和jar文件
在汇编文件中:
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.greg:child1</include>
</includes>
<binaries>
<outputDirectory>modules/maven-assembly-plugin</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
符合事实的
com.greg:child1
模块/maven汇编插件
错误的
在这里,只需添加上面的一行即可获取jar文件,如下所示:
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.greg:child1</include>
</includes>
<binaries>
<outputDirectory>modules/maven-assembly-plugin</outputDirectory>
<outputFileNameMapping>${module.artifactId}.${module.extension}</outputFileNameMapping>
<unpack>false</unpack>
</binaries>
</moduleSet>
符合事实的
com.greg:child1
模块/maven汇编插件
${module.artifactId}.${module.extension}
错误的
希望这能帮助其他人
参考资料:谢谢您的回复。但运行mvn package命令并不是在创建程序集。另外,binaries部分中输出目录的值应该是多少?我还在assembly.xml中保留了模块集。分发模块中的assembly.xml能否找到其他模块-子模块1和子模块2?更新分发POM后,我收到一个错误-[错误]未能对项目分发执行目标:无法解析项目com的依赖项。karthik:distribution:pom:1.0-SNAPSHOT:无法解析以下工件:com.karthik:child1:jar:1.0-SNAPSHOT,com.ssga.fi:child2:jar:1.0-SNAPSHOTIn