The problem is taht I get the following error qhile deploying my project to Glassfish:
java.lang.RuntimeException: Unable to load EJB module. DeploymentContext does not contain any EJB Check archive to ensure correct packaging
But, let us start on how the project structure looks like in Maven2...
I've build the following scenario:
MultiModuleJavaEEProject - parent module
-> model ---> packaged as jar
-> ejb1 ----> packaged as ebj
-> ejb2 ----> packaged as ebj
-> web ----> packaged as war
So model, ejb1, ejb2 and web are children/modules of the parent MultiModuleJavaEEProject.
_ejb1 depends on model.
_ejb2 depends on ejb1.
_web depends on ejb2.
the pom's look like:
_parent:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.dyndns.geraldhuber.testing</groupId>
<artifactId>MultiModuleJavaEEProject</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>MultiModuleJavaEEProject</name>
<url>http://maven.apache.org</url>
<modules>
<module>model</module>
<module>ejb1</module>
<module>ejb2</module>
<module>web</module>
</modules>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.2</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
<jarName>${project.groupId}.${project.artifactId}-${project.version}</jarName>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
_model:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>testing</groupId>
<artifactId>MultiModuleJavaEEProject</artifactId>
<version>1.0</version>
</parent>
<artifactId>model</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>model</name>
<url>http://maven.apache.org</url>
</project>
_ejb1:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>testing</groupId>
<artifactId>MultiModuleJavaEEProject</artifactId>
<version>1.0</version>
</parent>
<artifactId>ejb1</artifactId>
<packaging>ejb</packaging>
<version>1.0</version>
<name>ejb1</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.ejb</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>testing</groupId>
<artifactId>model</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
_ejb2:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>testing</groupId>
<artifactId>MultiModuleJavaEEProject</artifactId>
<version>1.0</version>
</parent>
<artifactId>ejb2</artifactId>
<packaging>ejb</packaging>
<version>1.0</version>
<name>ejb2</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.ejb</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>testing</groupId>
<artifactId>ejb1</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
_web:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>MultiModuleJavaEEProject</artifactId>
<groupId>testing</groupId>
<version>1.0</version>
</parent>
<groupId>testing</groupId>
<artifactId>web</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>web Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.ejb</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>testing</groupId>
<artifactId>ejb2</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<finalName>web</finalName>
</build>
</project>
And the model is just a simple Pojo:
package testing.model;
public class Data {
private String data;
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}
And the ejb1 contains only one STATELESS ejb.
package testing.ejb1;
import javax.ejb.Stateless;
import testing.model.Data;
@Stateless
public class DataService {
private Data data;
public DataService(){
data = new Data();
data.setData("Hello World!");
}
public String getDataText(){
return data.getData();
}
}
As well as the ejb2 is only a stateless ejb:
package testing.ejb2;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import testing.ejb1.DataService;
@Stateless
public class Service {
@EJB
DataService service;
public Service(){
}
public String getText(){
return service.getDataText();
}
}
And the web module contains only a Servlet:
package testing.web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import testing.ejb2.Service;
public class SimpleServlet extends HttpServlet {
@EJB
Service service;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println( "SimpleServlet Executed" );
out.println( "Text: "+service.getText() );
out.flush();
out.close();
}
}
And the web.xml file in the web module looks like:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>simple</servlet-name>
<servlet-class>testing.web.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>simple</servlet-name>
<url-pattern>/simple</url-pattern>
</servlet-mapping>
</web-app>
So no further files are set up by me. There is no ejb-jar.xml in any ejb files, because I'm using EJB 3.1. So I think ejb-jar.xml descriptors are optional. I this right?
But the problem is, the already mentioned error:
java.lang.RuntimeException: Unable to load EJB module. DeploymentContext does not contain any EJB Check archive to ensure correct packaging
Can anybody help?