简体   繁体   中英

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. The most important job is to build a project which depends on several other projects for Java classes. 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. I exported these dependent projects to jars and then created a Maven dependency using the following command line:

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. 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. I tried to use Modules in pom.xml but It shows error as below:

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/
+--- project 1 - jar/
|
+--- project 2 - jar/

instead you have to reorganize your project and join everything in project with packaging type set to "pom"

pom/
+--- war/
|
+--- project 1 - jar/
|
+--- project 2 - jar/

Maven requires parent pom to be of type "pom".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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