no

How to create a modularized ear project in maven

This post is one way of creating a typical javaee6 maven project that contains ear, web, ejb and api. The output of course is an ear file th...

This post is one way of creating a typical javaee6 maven project that contains ear, web, ejb and api. The output of course is an ear file that contains (web, ejb and api).

How it looks like (assuming our top project is named ipiel):
+ipiel
 +ipiel-ear
 +ipiel-web
 +ipiel-api
 +ipiel-ejb

*Note that ipiel, can also be a child of a another project, which could be a main project where ipiel is just a component.

How to create the 5 listed maven projects above (I'm assuming you have eclipse with maven plugin installed):
1.) ipiel (the main pom project)
  a.) In eclipse create a new maven project, skip archetype selection so it will only create a maven project that has a src folder no main/test.
  b.) groupId=com.ipiel
       artifactId=ipiel
       packaging=pom
       version=leave the default

2.) ipiel-api (where interface is declared that is shared between ejb and web)
  a.) Right click the ipiel project and select new->maven module
  b.) Since this will contain java files, select maven-archetype-quickstart, you can filter "quickstart"
  c.) groupId=com.ipiel
       artifactId=ipiel-api
       packaging=jar
       version=leave the default
  d.) Create a class Bird and add a method fly.

3.) ipiel-ejb (the backing/manage bean)
  a.) Right click the ipiel project and select new->maven module
  b.) Since this will contain java files, select maven-archetype-quickstart, you can filter "quickstart"

  c.) groupId=com.ipiel
       artifactId=ipiel-ejb
       packaging=ejb
       version=leave the default
  d.) Add dependency to ipiel-api, and implement the Bird interface, in a class let's say Eagle.
<dependency>
 <groupId>com.ipiel</groupId>
 <artifactId>ipiel-api</artifactId>
 <version>0.0.1-SNAPSHOT</version>
</dependency>

4.) ipiel-web (the ui project, where you define your xhtml files)
  a.) Right click the ipiel project and select new->maven module
  b.) In the maven filter enter "web" and select org.codehaus.mojo.archetypes webapp-javaee6.
       It's a simple web archetype and we need to add some files to it.
    1.) Add a new source folder /src/main/resources.
    2.) Inside /src/main/resources create 2 folders /META-INF and /WEB-INF
    3.) Normally we have beans.xml and web.xml inside /WEB-INF folder and /META-INF contains MANIFEST.MF
  c.) groupId=com.ipiel
       artifactId=ipiel-web
       packaging=war
       version=leave the default
  d.) Make sure that you add maven-war-plugin in pom.xml.
<plugin>
 <artifactId>maven-war-plugin</artifactId>
 <version>2.2</version>
 <configuration>
  <!-- In version 2.1-alpha-1, this was incorrectly named warSourceExcludes -->
  <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
  <archive>
   <manifest>
    <addClasspath>true</addClasspath>
    <classpathPrefix>lib/</classpathPrefix>
   </manifest>
  </archive>
 </configuration>
</plugin>
  e.) The web project is also dependent on ipiel-api, since it needs to call it's backing bean from the ipiel-ejb project.

5.) ipiel-config (where I normally place persistence and resource files)
  a.) groupId=com.ipiel
       artifactId=ipiel-config
       packaging=pom
       version=leave the default
  b.) Create a new maven module, and select maven-archetype-quickstart, you can filter "quickstart"
I defined where my resources are in this project:
<build>
 <resources>
  <resource>
   <directory>src/main/resources</directory>
   <filtering>true</filtering>
  </resource>
 </resources>
</build>

6.) ipiel-ear (the output project)
  a.) Create a new maven module project, skip archetype selection, so we have a basic maven project
  b.) groupId=com.ipiel
       artifactId=ipiel-ear
       packaging=ear
       version=leave the default
  c.) 

Related

source-code-management 8244715007099948656

Post a Comment Default Comments

item