Maven ear Plugin

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

Each Maven module creates just one artifact, and as EARs are aggregations of multiple artifacts, a project that produces an EAR has at least two modules: the module that produces the EAR and the module that produces the actual content (WAR, JAR, etc.).

Playground Example

The following example shows how to build an EAR that contains a library JAR and a WAR. is a three-module Maven project.

The interesting pom.xml that builds the EAR is found here:


https://github.com/NovaOrdis/playground/blob/master/jee/ear/war-and-lib/ear/pom.xml



!!!Working EAR Module POM example

{{{ <project>

   <modelVersion>4.0.0</modelVersion>
   <name>TimeSnap Enterprise Archive Module</name>
   <parent>
       <groupId>org.novaordis.timesnap</groupId>
       <artifactId>root</artifactId>
       <version>r27</version>
   </parent>
   <groupId>org.novaordis.timesnap</groupId>
   <artifactId>timesnap</artifactId>
   <packaging>ear</packaging>
   <build>
       <plugins>
           <plugin>
               <artifactId>maven-ear-plugin</artifactId>
               <configuration>
                   <jboss>
                       <version>4</version>
                   </jboss>
                   <modules>
                       <sarModule>
                           <groupId>org.novaordis.timesnap</groupId>
                           <artifactId>timesnap-service</artifactId>
                       </sarModule>
                       <webModule>
                           <groupId>org.novaordis.timesnap</groupId>
                           <artifactId>timesnap-webapp</artifactId>
                           <context-root>/timesnap</context-root>
                       </webModule>
                       <jarModule>
                           <groupId>junit</groupId>
                           <artifactId>junit</artifactId>
                           <excluded>true</excluded>
                       </jarModule>
                       <jarModule>
                           <groupId>log4j</groupId>
                           <artifactId>log4j</artifactId>
                           <excluded>true</excluded>
                       </jarModule>
                   </modules>
               </configuration>
           </plugin>
       </plugins>
   </build>
   <dependencies>
       <dependency>
           <groupId>org.novaordis.timesnap</groupId>
           <artifactId>timesnap-service</artifactId>
           <version>${project.version}</version>
           <type>sar</type>
       </dependency>
       <dependency>
           <groupId>org.novaordis.timesnap</groupId>
           <artifactId>timesnap-webapp</artifactId>
           <version>${project.version}</version>
           <type>war</type>
       </dependency>
   </dependencies>

</project>

}}}

!!!Including a Third-Party Application Module

{{{

<build>
   <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-ear-plugin</artifactId>
       <configuration>
          [...]
          <modules>
            <jarModule>
              <groupId>artifactGroupId</groupId>
              <artifactId>artifactId</artifactId>
              <includeInApplicationXml>true</includeInApplicationXml>
            </jarModule>
         </modules>
       </configuration>
     </plugin>
   </plugins>
 </build>

}}}