Home > Articles > Programming

  • Print
  • + Share This
Like this article? We recommend

Wrapping it All Up

The final step is to wrap up all these subprojects and place them into an ear file. To do this, a project.xml file that is dependent on all of the subprojects and defines how they apply to the ear file needs to be created.

<project>
 <extend>common/project.xml</extend>
  <artifactId>example</artifactId>

  <dependencies>
   <dependency>
    <groupId>${pom.groupId}</groupId>
    <artifactId>ejb</artifactId>
    <version>${pom.currentVersion}</version>
    <type>ejb</type>
    <properties>
     <ear.bundle>true</ear.bundle>
    </properties>
   </dependency>
   <dependency>
    <groupId>${pom.groupId}</groupId>
    <artifactId>util</artifactId>
    <version>${pom.currentVersion}</version>
    <properties>
     <ear.bundle>true</ear.bundle>
    </properties>
   </dependency>
   <dependency>
    <groupId>${pom.groupId}</groupId>
    <artifactId>web</artifactId>
    <version>${pom.currentVersion}</version>
    <type>war</type>
    <properties>
     <ear.bundle>true</ear.bundle>
     <ear.appxml.war.context-root>example</ear.appxml.war.context-root>
    </properties>
   </dependency>
  </dependencies>
</project>

In this project.xml file, I defined dependencies on everything that will need to be included inside of the ear and how those files are to be utilized.

The project.properties file for this top-level project is as follows:

maven.multiproject.includes=**/project.xml
maven.multiproject.excludes=project.xml,common/project.xml

maven.ear.appxml.generate=true

This properties file instructs Maven to generate the application.xml file based on the dependency settings in the project.xml file. In addition, it defines which subprojects are to be included in the multi-project build. In this case, all the subprojects—with the exception of the common project—are to be included. I also excluded the top-level project to avoid a circular build.

The final file is the top-level maven.xml file:

<project default="example:build" xmlns:j="jelly:core">
 <goal name="example:build">
   <j:set var="goal" value="example:build"/>
   <attainGoal name="multiproject:goal"/>
   <attainGoal name="ear"/>
  </goal>

  <goal name="example:clean" prereqs="multiproject:clean,clean"/>
</project>

In this maven.xml file, I defined two new goals to be used with this project. The shorter one simply cleans all the subprojects and the current project. The call to multiproject:clean will call all of the subproject's clean goal.

The second goal, example:build, executes the example:build goal on all the included subprojects, which allows each subproject to define how it should be built. I also set the example:build goal to be the default goal for the main project. After the subprojects are built, the goal will execute the ear goal on the top-level project, which will produce the final ear file.

At this top level, I can now call example:build; it will resolve all the dependencies, build each of the subprojects, install them into the local repository, and finally produce the ear file.

  • + Share This
  • 🔖 Save To Your Account