简体   繁体   English

如何使用Maven使用对多个相关Java项目的Java类引用来构建Java EE项目?

[英]How to use Maven to build a Java EE project with Java class references to several dependent Java projects?

I'm a rookie in Maven and recently I started using Maven to manage our Java EE project. 我是Maven的新手,最近我开始使用Maven来管理我们的Java EE项目。 The most important job is to build a project which depends on several other projects for Java classes. 最重要的工作是构建一个项目,该项目依赖于Java类的其他几个项目。 Firstly, I found it cannot detect these Java class even though I configured these Java projects as library references in the main project and Deployment Assembly, so I tried another approach. 首先,我发现即使我在主项目和Deployment Assembly中将这些Java项目配置为库引用,也无法检测到这些Java类,因此我尝试了另一种方法。 I exported these dependent projects to jars and then created a Maven dependency using the following command line: 我将这些依赖项目导出到jar中,然后使用以下命令行创建Maven依赖项:

mvn install:install-file -DgroupId=MY_GROUP_ID -DartifactId=ARTIFACT_ID -Dversion=1.0.0 -Dpackaging=jar -Dfile=MY_JAR.jar

And then I added these dependencies in the main project's pom.xml, and it absolutely works. 然后,我将这些依赖项添加到主项目的pom.xml中,它绝对有效。 But this approach is very hard to popularize among our team members, since it requires manually running a script. 但是这种方法很难在我们的团队成员中普及,因为它需要手动运行脚本。

So I'm wondering if there is a plugin for Maven can meet my goal, to build a main project with the project references without exporting dependent projects to jars. 所以我想知道是否有Maven插件可以满足我的目标,即使用项目引用构建主项目,而无需将相关项目导出到jar。 I tried to use Modules in pom.xml but It shows error as below: 我尝试在pom.xml中使用模块,但显示错误如下:

Project build error: 'packaging' with value 'war' is invalid. Aggregator projects require 'pom' as packaging.

Can anybody help me? 有谁能够帮助我? Thanks very much. 非常感谢。

You are getting this error because you are trying to join everything with maven pom file where packaging node is set to war: 之所以出现此错误,是因为您尝试将所有内容与打包节点设置为war的maven pom文件进行连接:

war/ 战争/
+--- project 1 - jar/ + ---项目1-jar /
| |
+--- project 2 - jar/ + ---项目2-jar /

instead you have to reorganize your project and join everything in project with packaging type set to "pom" 相反,您必须重新组织项目,并将包装类型设置为“ pom”的项目中的所有内容加入

pom/ pom /
+--- war/ + ---战争/
| |
+--- project 1 - jar/ + ---项目1-jar /
| |
+--- project 2 - jar/ + ---项目2-jar /

Maven requires parent pom to be of type "pom". Maven要求父pom的类型为“ pom”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM