java 将耳朵部署到 Glassfish 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3397178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:39:00  来源:igfitidea点击:

Error deploying ear to Glassfish

javajakarta-eeglassfishejb-3.0

提问by James

We have a EAR with 3 EJB modules. I am trying to deploy to glassfish but am hitting an error I can't explain or work out how best to identify.

我们有一个带有 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 ]|#]

I have checked the classes mentioned in the ClassNotFoundException and they are definetly in a Jar in the ear and I have no compilation issues in eclipse/maven.

我已经检查了 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

Any pointers are much appreciated.

任何指针都非常感谢。

James

詹姆士

回答by Pascal Thivent

Actually, you're not getting a ClassNotFoundException, you're getting a NoClassDefFoundErrorand I suspect some dependencies to be missing, as suggested by:

实际上,您没有得到ClassNotFoundException,而是得到了NoClassDefFoundError,我怀疑缺少某些依赖项,如建议的那样:

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

Where is that com.company.app.jms.IJmsSessionFactory?

那是哪里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?

我现在已经将耳朵简化为单个 ejb 模块,并且正在为 Lorg/apache/log4j/Logger 获取 NoClassDef,但是 log4j jar 也在耳朵中。感觉我一定在这里遗漏了一些基本的东西?

Where is the log4j.jarexactly? In /lib? Can you actually show the structure of your EAR? And please also show the MANIFEST.MFof your EJB-JAR.

具体在哪里log4j.jar?在/lib?你真的能展示你的 EAR 的结构吗?并且还请显示MANIFEST.MF您的 EJB-JAR。

Just in case, here is a relevant quote from Packaging EJB 3 Applications:

以防万一,这里有一个来自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.

打包 EJB-JAR

...

EJB-JAR 文件必须包含接口和 bean 类。它还可能包括任何帮助程序类。可以选择将帮助程序类打包在 EAR 文件中的单独 JAR 文件中。您有两个选择:

  • 包含帮助程序类的 JAR 可以打包在 EAR 文件的 lib 目录中。使用这种方法,打包的类将自动对 EAR 模块中的所有模块可见。
  • 如果您想将可见性限制为仅特定的 EJB-JAR 或 WAR 模块,您可以在包含 JAR 文件的 Class-Path 属性的模块的 Manifest.mf 文件中创建一个条目。

现在您已经了解了 EJB-JAR 的结构以及如何打包它,让我们来看看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.

根据您的评论,我认为我对我的问题有所了解。看起来我没有正确包装耳朵,我认为没有正确引用 Maven 依赖项。如果我只是构建我的 ejb jar,它不包括任何依赖的 jar。我应该在 pom 中指定一些东西来包含 jars ejb-jar 吗?我有构建插件<artifactId>maven-ejb-plugin</artifactId>和打包<packaging>ejb</packaging>集。

Bundling dependencies into an EJB-JAR is not supported (see MEJB-3) mostly because jar-within-jar is not part of the JAR specification(and might not be supported by all EJB container) and does not comply with Sun's advice regarding J2EE packagingin general.

不支持将依赖项捆绑到 EJB-JAR 中(请参阅MEJB-3),主要是因为 jar-within-jar 不是JAR 规范的一部分(并且可能并非所有 EJB 容器都支持)并且不符合Sun 关于 J2EE 的建议包装一般。

So while you may ignore this rule (see this trickor this one), the standard way would be to package the EJB-JAR and all the JARs it depends on in an EAR. This is my recommendation and I think that this post might help: Because I always forget how to use maven-ear-plugin.

因此,尽管你可以忽略此规则(见这一招还是这一个),该标准的方式是打包EJB-JAR和所有它在EAR依赖于JAR文件。这是我的建议,我认为这篇文章可能会有所帮助:因为我总是忘记如何使用 maven-ear-plugin