You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Thai Dang Vu <dx...@yahoo.com> on 2011/10/25 22:33:33 UTC
How to use maven to build an EAR project including web & ejb modules?
I used org.codehaus.mojo.archetypes:pom-root:1.1 to create a parent project (named `rbs'). Then I used org.codehaus.mojo.archetypes:ejb-jee5:1.3 to create 2 ejb child projects (named `ejb-group1' and `ejb-group2'), used org.codehaus.mojo.archetypes:webapp-jee5:1.3 to create a web child project (named `dashboard') and finally used org.codehaus.mojo.archetypes:ear-jee5:1.4 to create an ear project (named `ear-only1').
The generated parent pom.xml looks like this:
<project ...>
<modelVersion>4.0.0</modelVersion>
<groupId>home</groupId>
<artifactId>rbs</artifactId>
<version>0.1-snapshot</version>
<modules>
<module>dashboard</module>
<module>ejb-group1</module>
<module>ejb-group2</module>
<module>ear-only1</module>
</modules>
<packaging>pom</packaging>
<name>rbs</name>
</project>
The generated ejb project pom.xmls are (I post important lines only, the real pom.xml has dependencies on javaee-api, maven-ejb-plugin ...) :
<project ...>
<parent>
<artifactId>rbs</artifactId>
<groupId>home</groupId>
<version>0.1-snapshot</version>
</parent>
<artifactId>ejb-group1</artifactId>
<packaging>ejb</packaging>
<name>ejb-group1</name>
</project>
The generated web project pom.xml:
<project ...>
<parent>
<artifactId>rbs</artifactId>
<groupId>home</groupId>
<version>0.1-snapshot</version>
</parent>
<artifactId>dashboard</artifactId>
<packaging>war</packaging>
<name>dashboard</name>
</project>
The generated ear project pom.xml:
<project ...>
<parent>
<artifactId>rbs</artifactId>
<groupId>home</groupId>
<version>0.1-snapshot</version>
</parent>
<artifactId>ear-only1</artifactId>
<packaging>ear</packaging>
<name>ear-only1</name>
<dependencies>
<dependency>
<groupId>home</groupId>
<artifactId>dashboard</artifactId>
<version>0.1-snapshot</version>
</dependency>
<dependency>
<groupId>home</groupId>
<artifactId>ejb-group1</artifactId>
<version>0.1-snapshot</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<version>5</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>home</groupId>
<artifactId>dashboard</artifactId>
<contextRoot>dashboard</contextRoot>
</webModule>
<ejbModule>
<groupId>home</groupId>
<artifactId>ejb-group1</artifactId>
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
I have a few questions:
1. If I want to use slf4j in all modules, should I declare it in the <dependencyManagement> of the parent pom.xml and in each module pom.xml I declare it in <dependency> without its version? Then when the .ear file is generated (mvn ear:ear doesn't work in my case yet), where are all the slf4j .jars stored? In `lib' directory because of <defaultLibBundleDir>lib</defaultLibBundleDir> or somewhere else?
2. When I run mvn ear:generate-application-xml in the parent project, maven said it could not resolve dependencies for project home:ear-only1:ear:0.1-snapshot. How can I tell maven to do whatever needed with the web and ejb modules first and use the result to generate the application.xml file?
Regards.
How to use maven to build an EAR project including web & ejb modules?
Posted by Wayne Fay <wa...@gmail.com>.
> 1. If I want to use slf4j in all modules, should I declare it in the
> <dependencyManagement> of the parent pom.xml and in each
> module pom.xml I declare it in <dependency> without its version?
Sure.
> Then when the .ear file is generated (mvn ear:ear doesn't work in
> my case yet), where are all the slf4j .jars stored?
Potentially in numerous places. You probably want to read and apply:
http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html
> In `lib' directory because of <defaultLibBundleDir>lib
> </defaultLibBundleDir> or somewhere else?
Once you get your EAR working, you can just unzip the ear and check the
contents.
> 2. When I run mvn ear:generate-application-xml in the parent project,
> maven said it could not resolve dependencies for project home:ear-
> only1:ear:0.1-snapshot. How can I tell maven to do whatever needed
> with the web and ejb modules first and use the result to generate the
> application.xml file?
You should run "mvn install" in the parent project dir at least once to get
the jars and wars into your local cache, then it should work.
Wayne