将 EJB 和接口拆分为单独的模块 — 部署失败

发布于 2024-08-27 06:09:45 字数 1942 浏览 3 评论 0原文

无法按照本指南从 EAR 中“提取”我的接口和实体以从另一个 Web 应用程序使用它们:

  • 我 使用 NetBeans 6.8 和 Glassfish 3.0.1
  • “Java 类库”项目
    • 包含所有实体和接口
  • 包含“Java EE Application”项目的
    • 添加到项目中的类库,被打包到EAR中
    • 包含 EJB 实现、MDB、测试
  • “Java Web Application”项目
    • 类库添加到项目中,打包成WAR
    • 包含REST接口

WAR 中,当我构建和部署 Web 应用程序时,一切顺利。

当我构建 Java EE 应用程序时,我可以看到包含了 jar 文件(接口、实体)。但是,当我尝试部署 EAR 时,Glassfish 拒绝了它,并出现 java.lang.NoClassDefFoundError 错误:

[#|2010-03-28T18:25:59.875+0200|WARNING|glassfishv3.0|javax.enterprise.system.tools.deployment.org.glassfish.deployment.common|_ThreadID=28;_ThreadName=Thread-1;|Error in annotation processing: java.lang.NoClassDefFoundError: mvs/core/StoreServiceLocal|#]

[#|2010-03-28T18:25:59.876+0200|SEVERE|glassfishv3.0|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=28;_ThreadName=Thread-1;|Exception while deploying the app
java.lang.IllegalArgumentException: Invalid ejb jar [CoreServer]: it contains zero ejb. 
Note: 
1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message-driven bean. 
2. EJB3+ entity beans (@Entity) are POJOs and please package them as library jar. 
3. If the jar file contains valid EJBs which are annotated with EJB component level annotations (@Stateless, @Stateful, @MessageDriven, @Singleton), please check server.log to see whether the annotations were processed properly.

“mvs/core/StoreServiceLocal”是在库 jar 文件中定义的接口。

我做错了什么?

我正在使用 EJB3 Annotations,因此没有特定于 bean 的部署描述符:

mvs/core/ShopperService.java:

@Stateless
public class ShopperService implements ShopperServiceLocal, ShopperServiceRemote {
}

mvs/core/ShopperServiceLocal.java:

@Local
public interface ShopperServiceLocal {
}

I'm having trouble following this guide to "extract" my interfaces and entities from my EAR to use them from another Web Application:

  • I use NetBeans 6.8 and Glassfish 3.0.1
  • "Java Class Library" project
    • contains all the entities and interfaces
  • "Java EE Application" project
    • class library added to the project, is packaged into the EAR
    • contains EJB implementations, MDBs, Test
  • "Java Web Application" project
    • class library added to the project, is packaged into the WAR
    • contains REST interface

When I build and deploy the Web Application, all goes well.

When I build the Java EE application, I can see the jar-file (interfaces, entities) being included. But when I try to deploy the EAR, Glassfish refuses it with a java.lang.NoClassDefFoundError error:

[#|2010-03-28T18:25:59.875+0200|WARNING|glassfishv3.0|javax.enterprise.system.tools.deployment.org.glassfish.deployment.common|_ThreadID=28;_ThreadName=Thread-1;|Error in annotation processing: java.lang.NoClassDefFoundError: mvs/core/StoreServiceLocal|#]

[#|2010-03-28T18:25:59.876+0200|SEVERE|glassfishv3.0|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=28;_ThreadName=Thread-1;|Exception while deploying the app
java.lang.IllegalArgumentException: Invalid ejb jar [CoreServer]: it contains zero ejb. 
Note: 
1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message-driven bean. 
2. EJB3+ entity beans (@Entity) are POJOs and please package them as library jar. 
3. If the jar file contains valid EJBs which are annotated with EJB component level annotations (@Stateless, @Stateful, @MessageDriven, @Singleton), please check server.log to see whether the annotations were processed properly.

'mvs/core/StoreServiceLocal' is an interface which is defined in the library jar file.

What am I doing wrong?

I'm using EJB3 Annotations, so there is no bean-specific deployment descriptor:

mvs/core/ShopperService.java:

@Stateless
public class ShopperService implements ShopperServiceLocal, ShopperServiceRemote {
}

mvs/core/ShopperServiceLocal.java:

@Local
public interface ShopperServiceLocal {
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

攒一口袋星星 2024-09-03 06:09:45

您的“Java EE 应用程序”项目必须包含接口(当前无法在运行时加载,因此出现 NoClassDefFoundError)。如果您想从另一个 Web 应用程序调用 EJB,请创建一个额外的“客户端”jar(仅包含接口)。

Your "Java EE Application" project must contain the interfaces (that currently can't be loaded at runtime, hence the NoClassDefFoundError). And If you want to call the EJBs from another webapp, create an additional "client" jar (with the interfaces only).

失而复得 2024-09-03 06:09:45

我不确定上面列出的 EAR 文件的详细结构。 EAR 文件“内部”应该是一个 WAR 文件(对于 Web 容器)和另一个包含 EJB(对于 EJB 容器)的 JAR 文件。两者都必须了解 EJB 接口,因为它们相应的容器具有单独的类加载器。

如果您不需要完整的 EJB 功能,那么 EJB lite(随 EJB 3.1 一起提供)允许您创建一个 WAR 文件,您可以将这两个文件放入其中。例如,该 WAR 可以包含您的 EJB 和 servlet。这使您只需一个 WAR 文件即可更轻松地进行部署。但是,只有当您的 EJB 不需要提供任何远程接口时,EJB lite 才有用。

如果您的 EJB 需要远程接口,那么 EAR 文件是正确的选择。此 EAR 文件应包含用于 Web 目的的 WAR 文件和用于 EJB 定义的 JAR 文件。

I'm not sure about the detailed structure of your EAR file you listed above. 'Within' the EAR file should be one WAR file (for the web container) and another JAR file which contains your EJB (for the EJB container). Both have to know about the EJB interfaces as their appropriate containers have separate class loaders.

If you don't need full blown EJB functionality then EJB lite (which comes with EJB 3.1) allows you just to create one WAR file where you can put both in. This WAR could contain your EJBs and servlets for instance. This gives you an easier deployment with just one WAR file. But EJB lite is only helpful if your EJBs don't need to provide any remote interfaces.

If you need remote interfaces for your EJBs then an EAR file is the right way. This EAR file should contain a WAR file for web purposes and a JAR files for your EJB definitions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文