miércoles, 4 de mayo de 2016

Create a clean and complete EAR project with Maven (ear, war, ejb modules)

These orders are taken from the ones Netbeans uses when you create a New → Maven → Enterprise Application. It uses some nice archetypes from org.codehaus.mojo.archetypes:

cd C:\apps

mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=pom-root -DarchetypeVersion=1.1 -DarchetypeRepository=http://repo.maven.apache.org/maven2 -DgroupId=co.com.acme -DartifactId=myApp -Dversion=1.0-SNAPSHOT -Dpackage=co.com.acme.app -Dbasedir=C:\apps -Darchetype.interactive=false --batch-mode archetype:generate

cd C:\apps\myApp

mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=ear-javaee6 -DarchetypeVersion=1.5 -DarchetypeRepository=http://repo.maven.apache.org/maven2 -DgroupId=co.com.acme -DartifactId=myApp-ear -Dversion=1.0-SNAPSHOT -Dbasedir=C:\apps\myApp -Darchetype.interactive=false --batch-mode archetype:generate

mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=webapp-javaee6 -DarchetypeVersion=1.5 -DarchetypeRepository=http://repo.maven.apache.org/maven2 -DgroupId=co.com.acme -DartifactId=myApp-web -Dversion=1.0-SNAPSHOT -Dbasedir=C:\apps\myApp  -Darchetype.interactive=false --batch-mode archetype:generate

mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=ejb-javaee6 -DarchetypeVersion=1.5 -DarchetypeRepository=http://repo.maven.apache.org/maven2 -DgroupId=co.com.acme -DartifactId=myApp-ejb -Dversion=1.0-SNAPSHOT -Dbasedir=C:\apps\myApp -Darchetype.interactive=false --batch-mode archetype:generate

Resulting structure:


It is needed however to include some dependencies between the projects:

Edit C:\apps\myApp\myApp-ear\pom.xml and include:


    <dependencies>
        <dependency>
            <groupId>co.com.acme</groupId>
            <artifactId>myApp-ejb</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>ejb</type>
        </dependency>
        <dependency>
            <groupId>co.com.acme</groupId>
            <artifactId>myApp-web</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
    </dependencies>

Example:


Then you can do a C:\apps\myApp>mvn install obtaining the following EAR:





No hay comentarios: