How to build an EAR project with EJB and WAR in maven?

I tried to create an EAR project with EJB and WAR, but I have some problems. I am creating a main project in IntelliJ IDEA from Archetype:

<dependency> <groupId>org.codehaus.mojo.archetypes</groupId> <artifactId>ear-javaee6</artifactId> <version>1.5</version> </dependency> 

Then I created an EJB module from Archetype:

 <dependency> <groupId>org.codehaus.mojo.archetypes</groupId> <artifactId>ejb-javaee6</artifactId> <version>1.5</version> </dependency> 

And then I created a second module from Archetype:

 <dependency> <groupId>javax.faces</groupId> <artifactId>javax.faces-war-archetype</artifactId> <version>2.2</version> </dependency> 

Then I added the dependencies to the main pom.xml:

 <!-- Define the versions of your ear components here --> <dependencies> <dependency> <groupId>QCforCC-main</groupId> <artifactId>QCforCC-ejb</artifactId> <version>1.0-SNAPSHOT</version> <type>ejb</type> </dependency> <dependency> <groupId>QCforCC-main</groupId> <artifactId>QCforCC-war</artifactId> <version>1.0-SNAPSHOT</version> <type>war</type> </dependency> </dependencies> 

And then I tried to build a project - using maven clean and instal. But I have an error:

[ERROR] Projects in the reactor contain a circular link: Edge between 'Vertex {label =' QCforCC-main: QCforCC-war: 1.0-SNAPSHOT '}' and 'Vertex {label =' QCforCC-main: QCforCC-ejb: 1.0-SNAPSHOT '}' represents the loop in the graph QCforCC-main: QCforCC-ejb: 1.0-SNAPSHOT โ†’ QCforCC-main: QCforCC-war: 1.0-SNAPSHOT โ†’ QCforCC-main: QCforCC-ejb: 1.0-SNAPSHOT โ†’ [Help 1] [ERROR] [ERROR] To see the complete error stack error, rerun Maven with the -e switch. [ERROR] Restart Maven with the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectCycleException

Process terminated with exit code 1

And in the EAR pom.xml I have:

 <modules> <module>QCforCC-ejb</module> <module>QCforCC-war</module> </modules> <packaging>pom</packaging> 

But if I change <packaging>pom</packaging> to <packaging>ear</packaging> IDEA shows an error in the popup:

There were some problems processing the POM: [WARNING] 'build.plugins.plugin. (groupId: artifactId) 'must be unique, but a duplicate plugin declaration was found org.apache.maven.plugins: maven-ear-plugin @ line 41, column 21 [ERROR] "packaging" with the value "ear" is invalid. Aggregator designs require "pom" as packaging. @ row 12, column 16

+6
source share
2 answers

I highly recommend you understand how multi-module builds work. Sonatype's book has a wonderful chapter that describes in great detail.

To create an EAR with EJB and WAR, you really need three modules for EJB, WAR, and EAR. Parent POM just holds everything together and has a POM packaging type.

So the parent pom.xml should look like this:

 <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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.sonatype.mavenbook.multi</groupId> <artifactId>simple-parent</artifactId> <packaging>pom</packaging> <version>1.0</version> <name>Multi Chapter Simple Parent Project</name> <modules> <module>ejb-module</module> <module>war-module</module> <module>ear-module</module> </modules> </project> 

Then each of the child POMs will look like this:

EJB module / pom.xml:

 <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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.sonatype.mavenbook.multi</groupId> <artifactId>simple-parent</artifactId> <version>1.0</version> </parent> <artifactId>ejb-module</artifactId> <packaging>ejb</packaging> </project> 

war module /pom.xml

 <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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.sonatype.mavenbook.multi</groupId> <artifactId>simple-parent</artifactId> <version>1.0</version> </parent> <artifactId>war-module</artifactId> <packaging>war</packaging> <name>simple-webapp Maven Webapp</name> <dependencies> <dependency> <groupId>org.sonatype.mavenbook.multi</groupId> <artifactId>ejb-module</artifactId> <version>1.0</version> </dependency> </dependencies> </project> 

ear module / pom.xml:

 <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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.sonatype.mavenbook.multi</groupId> <artifactId>simple-parent</artifactId> <version>1.0</version> </parent> <artifactId>ear-module</artifactId> <packaging>ear</packaging> <name>EAR module</name> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-ear-plugin</artifactId> <version>2.10.1</version> <configuration> <ejbModule> <groupId>org.sonatype.mavenbook.multi</groupId> <artifactId>ejb-module</artifactId> <bundleFilename>ejb-module.jar</bundleFilename> </ejbModule> <webModule> <groupId>org.sonatype.mavenbook.multi</groupId> <artifactId>war-module</artifactId> <contextRoot>/foo</contextRoot> </webModule> </configuration> </plugin> </plugins> </build> </project> 
+8
source
 > 1. parent QCforCC-parent : <artifactId>QCforCC-parent</artifactId> <packaging>pom</packaging> ... ... <modules> <module>QCforCC-ear</module> <module>QCforCC-ejb</module> <module>QCforCC-war</module> </modules> > 2. QCforCC-ear : <artifactId>QCforCC-ear</artifactId> <packaging>ear</packaging> ... ... <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-ear-plugin</artifactId> <configuration> <version>5</version> <displayName>XXXXXXXX</displayName> <modules> <webModule> <moduleId>WebModule_XXX</moduleId> <groupId>${project.groupId}</groupId> <artifactId>>QCforCC-war</artifactId> <contextRoot>XXXXXXXX</contextRoot> </webModule> <jarModule> <groupId>${project.groupId}</groupId> <artifactId>QCforCC-ejb</artifactId> </jarModule> </modules> </configuration> </plugin> </plugins> 
0
source

All Articles