[英]Maven build with dependent projects
I am working on Java projects using maven and eclipse IDE. 我正在使用Maven和Eclipse IDE进行Java项目。
I have 3 projects namely P1, P2 and Main Project 我有3个项目,分别是P1,P2和Main Project
I have individual poms for P1, P2, Main Project, I have included P1, P2 as modules for Main Project and Main project is accepting packaging as pom only 我为P1,P2,主项目设置了单独的pom,我将P1,P2作为主项目的模块包含在内,并且主项目仅接受pom包装
If I change the packaging to war I get below error 如果我把包装换成战争,我会得到以下错误
Project build error: 'packaging' with value 'war' is invalid.
项目构建错误:值为“ war”的“包装”无效。 Aggregator projects require 'pom' as packaging.
聚合器项目需要“ pom”作为包装。
I wanted to build a war consisting of P1, P2 and Main Project class files in the war generated. 我想在产生的战争中建立一场由P1,P2和Main Project类文件组成的战争。
Can anyone give any pointers to achieve the same 任何人都可以提供任何指针以实现相同的目标
Thanks in Advance 提前致谢
You can't mix packaging types ( pom
and war
). 您不能混合包装类型(
pom
和war
)。 You need to introduce a fourth POM: 您需要引入第四个POM:
<project>
<groupId>org.example</groupId>
<artifactId>modules</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>P1</module>
<module>P2</module>
<module>Main</module> <!-- This contains your WAR -->
</modules>
...
</project>
Your project Main
depends on P1
and P2
. 您的项目
Main
取决于P1
和P2
。 Maven/Eclipse will figure out the build order for you. Maven / Eclipse将为您确定构建顺序。 You don't even need to import the
module
artifact in Eclipse if you don't want to, but you probably need to install the top POM at least once. 如果不想,甚至不需要在Eclipse中导入
module
构件,但是您可能至少需要安装一次顶级POM。
You can also put common configurations in the above POM at let the sub-modules inherit from it if you like. 您还可以在上面的POM中放入通用配置,如果愿意,可以让子模块从其继承。
Packaging POM is used for aggregation of the modules, their common dependencies (via Dependency Management section) or plugins (via Plugin Management section) etc. 打包POM用于模块,其公共依赖项(通过“依赖关系管理”部分)或插件(通过“插件管理”部分)的聚合。
In your case, you have to move the sources from the "Main Project" with packaging POM to another module, ex.: P0
. 在您的情况下,必须将源从打包了POM的“主项目”移到另一个模块,例如:
P0
。 Then you should have a packaging WAR on this P0
module. 然后,您应该在此
P0
模块上有包装的WAR。 Additionally, the P0 module can be dependent on P1
and P2
module. 另外,P0模块可以依赖于
P1
和P2
模块。
You may have project structure like this: 您可能具有以下项目结构:
Main Project
- packaging POM with modules: P0
, P1
, P2
Main Project
-带模块的包装POM: P0
, P1
, P2
P0
- packaging WAR with the sources from Main Project, dependent on: P1
, P2
P0
将WAR与Main Project一起打包,取决于: P1
, P2
P1
- packaging JAR P1
包装JAR P2
- packaging JAR P2
包装JAR When you build the Main Project with mvn package
, you will have a WAR file in /target
directory of P0
module. 使用
mvn package
构建Main Project时,您将在P0
模块的/target
目录中拥有一个WAR文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.