java - 将耳朵部署到 Glassfish 时出错

标签 java jakarta-ee glassfish ejb-3.0

我们有一个带有 3 个 EJB 模块的 EAR。我正在尝试部署到 glassfish,但遇到了一个错误,我无法解释或弄清楚如何最好地识别。

[#|2010-08-03T14:39:15.570+0100|INFO|glassfish3.0.1|javax.enterprise.system.tools.deployment.org.glassfish.deployment.common|_ThreadID=28;_ThreadName=Thread-1;|[AutoDeploy] Selecting file /export/home/myapp/apps/domains/myapp/autodeploy/App-ear.ear for autodeployment.|#]

[#|2010-08-03T14:39:18.654+0100|WARNING|glassfish3.0.1|javax.enterprise.system.tools.deployment.org.glassfish.deployment.common|_ThreadID=28;_ThreadName=Thread-1;|Error in annotation processing: java.lang.NoClassDefFoundError: com/company/app/controller/IMessagingProcessor|#]

[#|2010-08-03T14:39:20.470+0100|SEVERE|glassfish3.0.1|global|_ThreadID=28;_ThreadName=Thread-1;|Class [ Lcom/company/app/jms/IJmsSessionFactory; ] not found. Error while loading [ class com.company.app.eventprocessor.provider.EventProvider ]|#]

我已经检查了 ClassNotFoundException 中提到的类,它们肯定在耳边的 Jar 中,我在 eclipse/maven 中没有编译问题。

D:\Repository\App\AppEA\App-ear\target\App-ear.ear\CoreJms-1.0-SNAPSHOT.jar\com\company\app\controller\IMessagingProcessor.class

D:\Repository\App\AppEA\App-ear\target\App-ear.ear\EventProcessor-ejb-1.0-SNAPSHOT.jar\com\company\app\eventprocessor\provider\EventProvider.class

非常感谢任何指点。

詹姆斯

最佳答案

实际上,您没有得到 ClassNotFoundException ,你会得到一个 NoClassDefFoundError并且我怀疑缺少一些依赖项,如以下建议:

Class [ Lcom/company/app/jms/IJmsSessionFactory; ] not found. Error while loading [ class com.company.app.eventprocessor.provider.EventProvider 

那在哪里com.company.app.jms.IJmsSessionFactory


I have now cut the ear down to a single ejb module and am getting the NoClassDef for Lorg/apache/log4j/Logger however the log4j jar is also in the ear. It feels like I must be missing something fundamental here?

log4j.jar 在哪里确切地?在 /lib ?你真的能展示你的 EAR 的结构吗?并请出示 MANIFEST.MF你的 EJB-JAR。

以防万一,这是来自 Packaging EJB 3 Applications 的相关引述:

Packaging EJB-JAR

...

The EJB-JAR file must include the interfaces and bean classes. It may also include any helper classes. Optionally the helper classes may be packaged in a separate JAR file in the EAR file. You have two options:

  • The JAR containing helper classes may be packaged in the lib directory of the EAR file. Using this approach, the packaged classes will be automatically visible to all modules in the EAR module.
  • If you want to limit the visibility to only a specific EJB-JAR or WAR module, you can create an entry in the Manifest.mf file of the module that contains a Class-Path attribute to the JAR file.

Now that you know the structure of EJB-JAR and how to package it, let's look at the elements of ejb-jar.xml.


Based on your comments I think I am understadning my issue. It would appear I am not packaging the ear correctly, I don't think the maven dependencies are referenced correctly. If I simply build my ejb jar it does not include any of the dependant jars. Should I be specifying something in the pom to include the jars ejb-jar? I have the build plugin <artifactId>maven-ejb-plugin</artifactId> and packaging <packaging>ejb</packaging> set.

不支持将依赖项捆绑到 EJB-JAR 中(参见 MEJB-3),主要是因为 jar-within-jar 不是 JAR specification 的一部分(并且可能并非所有 EJB 容器都支持)并且不符合 Sun's advice regarding J2EE packaging一般而言。

因此,尽管您可以忽略此规则(请参阅 this trickthis one),但标准方法是将 EJB-JAR 及其依赖的所有 JAR 打包到一个 EAR 中。这是我的建议,我认为这篇文章可能会有所帮助:Because I always forget how to use maven-ear-plugin .

关于java - 将耳朵部署到 Glassfish 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3397178/

相关文章:

java - 如何用 Java (Eclipse) 编写程序来查找处理器的速度

java - Hibernate 的 Session.flush() 刷新了什么

java - 使用 GlassFish 部署 Java 应用程序时出错

java - JTextField 对齐错误。无法右对齐

java - 如何确定传入连接来自本地计算机

java - Android TabListener : onTabSelected - add fragment to back stack

java - 从具有 Web 服务的基本 Java 项目到可部署的 Glassfish 工件?

java - 用 JSP 的类文件而不是 JSP 本身来传送 WAR 更好吗?

java - Arquillian 测试未执行

java - 从实体生成表