users@glassfish.java.net

Re: Correct packaging for EJBs in WAR or EAR.

From: <glassfish_at_javadesktop.org>
Date: Thu, 22 Apr 2010 11:27:57 PDT

I think the best way is to divide your modules to EJB and WAR modules and deploy them in a ear project. It helps you to refuse the complexity so much. Though by JEE6 it is possible to deploy EJBs in WAR packages.

The following is the way you can structure an EAR module in Maven. Nevertheless, it is possible to omit a module with some simple modification to have for example one WAR project.
Structure of an EAR project in maven;

Project/pom.xml (pom1)

Project/Project-ejb
Project/Project-ejb/src/main/java
Project/Project-ejb/src/main/resources/META-INF/persistence.xml
Project/Project-ejb/pom.xml (pom2)

Project/Project-war
Project/Project-war/src/main/java
Project/Project-war/src/main/resources
Project/Project-war/src/main/webapp
Project/Project-war/src/main/webapp/WEB-INF/web.xml
Project/Project-war/pom.xml (pom3)

Project/Project-ear
Project/Project-ear/src/main/application/META-INF/application.xml
Project/Project-ear/pom.xml (pom4)

The following is a sample for pom files;

pom1;
- <project xmlns="http://maven ...>
  <modelVersion>4.0.0</modelVersion>
  <groupId>sampleGroupID</groupId>
  <artifactId>SampleArtifactID</artifactId>
  <packaging>pom</packaging>
  <name>Project</name>
  <version>1.0</version>
- <modules>
  <module>Project-ejb</module>
  <module>Project-web</module>
  <module>Project-ear</module>
  </modules>
  </project>


pom2;
- <project xmlns="http://maven ...>
  <modelVersion>4.0.0</modelVersion>
- <parent>
  <groupId>sampleGroupID</groupId>
  <artifactId>SampleArtifactID</artifactId>
  <version>1.0</version>
  </parent>
  <groupId>sampleGroupID</groupId>
  <artifactId>Project-ejb</artifactId>
  <packaging>ejb</packaging>
  <name>Project-ejb</name>
  <version>1.0</version>
...
  </project>


pom3;
- <project xmlns="http://maven ...>
  <modelVersion>4.0.0</modelVersion>
- <parent>
  <groupId>sampleGroupID</groupId>
  <artifactId>SampleArtifactID</artifactId>
  <version>1.0</version>
  </parent>
  <groupId>sampleGroupID</groupId>
  <artifactId>Project-web</artifactId>
  <packaging>war</packaging>
  <name>Project-web</name>
  <version>1.0</version>
...
  </project>

pom4;
- <project xmlns="http://maven ...>
  <modelVersion>4.0.0</modelVersion>
- <parent>
  <groupId>sampleGroupID</groupId>
  <artifactId>SampleArtifactID</artifactId>
  <version>1.0</version>
  </parent>
  <groupId>sampleGroupID</groupId>
  <artifactId>Project-ear</artifactId>
  <packaging>ear</packaging>
  <name>Project-ear</name>
  <version>1.0</version>
- <build>
- <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-ear-plugin</artifactId>
- <configuration>
  <version>5</version>
  </configuration>
  </plugin>
  </plugins>
  </build>
- <dependencies>
- <dependency>
  <groupId>sampleGroupID</groupId>
  <artifactId>Project-web</artifactId>
  <version>1.0</version>
  <type>war</type>
  </dependency>
- <dependency>
  <groupId>sampleGroupID</groupId>
  <artifactId>Project-ejb</artifactId>
  <version>1.0</version>
  <type>ejb</type>
  </dependency>
  </dependencies>
  </project>

The rest depends on your knowledge about maven.
Now it is clear that if you gonna have for example one WAR file, which of the preceding parts have to be omitted.
Also note that you have to manage the dependencies in each pom file.
Bests
Youness
[Message sent by forum member 'youness_teimoury']

http://forums.java.net/jive/thread.jspa?messageID=398549