Maven ear Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 29: Line 29:
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
<!DOCTYPE application PUBLIC
        "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
        "http://java.sun.com/dtd/application_1_3.dtd">
"http://java.sun.com/dtd/application_1_3.dtd">
<application>
<application>
   <display-name>ear-example</display-name>
   <display-name>ear-example</display-name>
  <module>
    <java>ear-embedded-lib-1.jar</java>
  </module>
   <module>
   <module>
     <web>
     <web>
       <web-uri>ear-embedded-web-application-1.war</web-uri>
       <web-uri>ear-embedded-web-application-1.war</web-uri>
       <context-root>/test</context-root>
       <context-root>/example</context-root>
     </web>
     </web>
   </module>
   </module>

Revision as of 22:43, 18 March 2016

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. It 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

Notes

  • The WAR dependency must be explicitly declared of type "war", otherwise the dependency management will attempt to find a JAR and fail.
  • The EAR plugin automatically generates an application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
	"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
	"http://java.sun.com/dtd/application_1_3.dtd">
<application>
  <display-name>ear-example</display-name>
  <module>
    <java>ear-embedded-lib-1.jar</java>
  </module>
  <module>
    <web>
      <web-uri>ear-embedded-web-application-1.war</web-uri>
      <context-root>/example</context-root>
    </web>
  </module>
</application>
  • If <jboss> is specified in the plugin's configuration, Maven will also generate a JBoss-specific deployment descriptor. Versions seem to be supported by default up to 5.

Including a Third-Party Application Module

Specify <includeInApplicationXml>true</includeInApplicationXml>:

<plugin>
  <artifactId>maven-ear-plugin</artifactId>
    <configuration>
      <modules>
        <jarModule>
          <groupId>io.novaordis.playground.jee.ear.war-and-lib</groupId>
          <artifactId>ear-embedded-lib</artifactId>
          <!--
                 If the following flag is not specified, the JAR will be embedded in the EAR's root
                 but no corresponding <java> <module> will be added to application.xml module list.
           -->
          <includeInApplicationXml>true</includeInApplicationXml>
        </jarModule>
        ...
      </modules>
   </configuration>
</plugin>