Enterprise Java Development@TOPIC@
Useful when need to deploy EJB with dependent artifacts or without WAR
|-- ejb-basic-ejb.jar `-- META-INF `-- application.xml
<project>
<groupId>info.ejava.examples.ejb.basicejb</groupId>
<artifactId>ejb-basic-ear</artifactId>
<packaging>ear</packaging>
<dependencies>
<!-- The EAR must have a scope=compile dependency on the EJB -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ejb-basic-ejb</artifactId>
<version>${project.version}</version>
<type>ejb</type>
</dependency>
</dependencies>
<build>
<plugins>
<!-- provide properties here to impact the EAR packaging -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<!-- eliminates use of version in EAR JNDI name portion -->
<applicationName>${project.artifactId}</applicationName>
<modules>
<!-- eliminates use of the version in the EJB JNDI name -->
<ejbModule>
<groupId>${project.groupId}</groupId>
<artifactId>ejb-basic-ejb</artifactId>
<bundleFileName>ejb-basic-ejb.jar</bundleFileName>
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
Add EAR artifact as a scope=compile dependency when deploying from separate (test) module
<dependencies>
...
<!-- packages being deployed must be a dependency -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ejb-basic-ear</artifactId>
<version>${project.version}</version>
<type>ear</type>
<scope>compile</scope>
</dependency>
...
</dependencies>
Declare EAR artifact to be deployed
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<!-- artifacts to deploy to server -->
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>ejb-basic-ear</artifactId>
<type>ear</type>
</deployable>
</deployables>
</configuration>
</plugin>
</plugins>
</build>