问题是我得到以下错误qhile将我的项目部署到Glassfish:
java.lang.RuntimeException: Unable to load EJB module. DeploymentContext does not contain any EJB Check archive to ensure correct packaging
但是,让我们开始讨论Maven2中的项目结构......
我构建了以下场景:
MultiModuleJavaEEProject - 父模块
- >型号--->打包成罐子
- > ejb1 ---->打包为ebj
- > ejb2 ---->打包为ebj
- >网络---->打包为战争
所以model,ejb1,ejb2和web是父MultiModuleJavaEEProject的子/模块。
_ejb1取决于型号 _ejb2取决于ejb1 _web取决于ejb2。
pom看起来像是:_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>
模型只是一个简单的Pojo:
package testing.model;
public class Data {
private String data;
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}
ejb1只包含一个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();
}
}
除了ejb2只是一个无国籍的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();
}
}
Web模块只包含一个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();
}
}
Web模块中的web.xml文件如下所示:
<!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>
所以我没有设置更多文件。任何ejb文件中都没有ejb-jar.xml,因为我使用的是EJB 3.1。所以我认为ejb-jar.xml描述符是可选的。我这样对吗? 但问题是,已经提到的错误:
java.lang.RuntimeException: Unable to load EJB module. DeploymentContext does not contain any EJB Check archive to ensure correct packaging
有人可以帮忙吗?
答案 0 :(得分:3)
我不知道为什么你有web.xml
(而不是使用注释)...但如果你真的想要,改变这个:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
进入这个:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
...
</web-app>
重建/重新部署。
答案 1 :(得分:2)
对于任何使用Glassfish 3.1和Eclipse 3.7,m2e 1.0和m2e-wtp集成的人来说: Glassfish的Eclipse WTP开始部署buggy in Glassfish 3.1的爆炸罐。至少使用Glassfish 3.1.1 Beta 1使Eclipse WTP集成再次工作。
要测试您是否受此问题影响,请测试从Eclipse导出WAR并使用Glassfish管理控制台手动部署WAR时是否一切正常。