Maven2多模块ejb 3.1项目-部署错误
问题是我在将项目部署到 Glassfish 时遇到以下错误:
java.lang.RuntimeException: Unable to load EJB module. DeploymentContext does not contain any EJB Check archive to ensure correct packaging
但是,让我们开始了解 Maven2 中的项目结构如何...
我构建了以下场景:
MultiModuleJavaEEProject - 父模块
->型号--->打包成jar
-> ejb1---->打包为 ebj
-> ejb2---->打包为 ebj
->网站---->打包为 war
所以模型、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
有人可以帮忙吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道为什么你有一个
web.xml
(而不是使用注释)...但如果你真的想要,将其更改为: 更改为:
并重建/重新部署。
I don't know why you have a
web.xml
(instead of using annotations)... But if you really want to, change this:Into this:
And rebuild/redeploy.
对于使用 Glassfish 3.1 和 Eclipse 3.7、m2e 1.0 和 m2e-wtp 集成遇到此问题的任何人:
Eclipse WTP for Glassfish 开始部署分解的 jar,这些 jar Glassfish 3.1 中存在错误。至少使用 Glassfish 3.1.1 Beta 1 来制作Eclipse WTP 集成再次工作。
要测试您是否受到此问题的影响,请测试当您从 Eclipse 导出 WAR 并使用 Glassfish 管理控制台手动部署它时一切是否正常。
For anybody who comes accross this using Glassfish 3.1 and Eclipse 3.7, m2e 1.0 and the m2e-wtp integration:
Eclipse WTP for Glassfish started deploying exploded jars which are buggy in Glassfish 3.1. Use Glassfish 3.1.1 Beta 1 at least to make the Eclipse WTP integration work again.
To test if you are affected by this issue, test if everything works when you export the WAR from Eclipse and deploy it manually using the Glassfish Admin Console.