简体   繁体   English

如何在EAR项目中部署EJB项目和JPA项目

[英]How to deploy EJB project and JPA project in EAR project

I create 2 projects one is EJB and one is JPA. 我创建了2个项目,一个是EJB,一个是JPA。 JPA project define entities classes, and persistent.xml. JPA项目定义实体类和persistent.xml。 EBJ project import JPA project, I defined EJB session bean to connect database by entity manager. EBJ项目导入JPA项目,我定义了EJB会话Bean以通过实体管理器连接数据库。 please refer below image for details. 请参考下图了解详情。 But when running on Jboss 7, error happend. 但是当在Jboss 7上运行时,发生了错误。

在此处输入图片说明

03:23:59,546 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.deployment.subunit."TestApps.ear"."TestEJB.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."TestApps.ear"."TestEJB.jar".POST_MODULE: Failed to p
rocess phase POST_MODULE of subdeployment "TestEJB.jar" of deployment "TestApps.ear"
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [rt.jar:1.6.0_22]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.6.0_22]
        at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_22]
Caused by: java.lang.RuntimeException: Error getting reflective information for class com.ejb.services.LotUpdatManagerBean with ClassLoader ModuleClassLoader for Module "deployment.TestApps.ear.TestEJB.jar:main" from Service Module Loader
        at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
        at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:58)
        at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:85)
        at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:70)
        at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:55)
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
        ... 5 more
Caused by: java.lang.NoClassDefFoundError: com/test/model/LotUpdates
        at java.lang.Class.getDeclaredMethods0(Native Method) [rt.jar:1.6.0_22]
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source) [rt.jar:1.6.0_22]
        at java.lang.Class.getDeclaredMethods(Unknown Source) [rt.jar:1.6.0_22]
        at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:65) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
        at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
        ... 10 more
Caused by: java.lang.ClassNotFoundException: com.test.model.LotUpdates from [Module "deployment.TestApps.ear.TestEJB.jar:main" from Service Module Loader]
        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
        ... 15 more

03:23:59,762 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "TestApps.ear" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.deployment.subunit.\"TestApps.ear\".\"TestEJB.jar\".POST_MODULE" => "org.jboss.msc.service.StartExce
ption in service jboss.deployment.subunit.\"TestApps.ear\".\"TestEJB.jar\".POST_MODULE: Failed to process phase POST_MODULE of subdeployment \"TestEJB.jar\" of deployment \"TestApps.ear\""}}
03:23:59,765 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015877: Stopped deployment TestEJB.jar in 2ms
03:23:59,767 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015877: Stopped deployment TestApps.ear in 4ms
03:23:59,768 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.deployment.subunit."TestApps.ear"."TestEJB.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."TestApps.ear"."TestEJB.jar".POST_MODULE: Failed to process phase POST_MODULE of subdeployment "TestE
JB.jar" of deployment "TestApps.ear"

I'm failed. 我失败了 Anyone can correct me, Show me the way to deploy(jpa project and ejb project in same ear). 任何人都可以纠正我,向我展示部署方式(jpa项目和ejb项目在同一耳朵)。

You have 2 potential options: 您有2个可能的选择:

  • if you TestJpa.jar is in ear\\lib folder it should be visible by default in ejb module (ensure that EAR is in 6.0 version) 如果您的TestJpa.jar位于ear\\lib文件夹中,则默认情况下它应该在ejb模块中可见(确保EAR为6.0版本)
  • manually add via Deployment Assembly in EJB project, the JPA project - should result in changes in the manifest file for EJB module. 在JPA项目中,通过Deployment Assembly在EJB项目中手动添加-应该会导致EJB模块的清单文件中的更改。

If you correctly configure it, using either way you should see the JPA project in the EJB Module > EAR Libraries in Eclipse, without need to add it as project in the Build Path 如果正确配置了它,则无论使用哪种方式,您都应该在Eclipse中的EJB Module > EAR Libraries中查看JPA项目,而无需将其添加为Build Path中的项目。

As follow up to our discussion in the comments i provide this "answer" as a first hook on what could possible have gone wrong. 作为我们在评论中的讨论的后续,我提供了这个“答案”,以作为对可能发生的错误的第一钩。

Regarding the EAR structure The structure of the package types EAR, WAR and JAR are well defined and must be followed to generate enterprise archives (EARs) that later will run on application servers like JBoss. 关于EAR结构包类型EAR,WAR和JAR的结构已得到很好的定义,必须遵循以生成企业归档文件(EAR),该归档文件以后将在诸如JBoss的应用服务器上运行。

You will find any required information on packaging under https://docs.oracle.com/javaee/6/tutorial/doc/bnaby.html (Note this is for Java EE 6). 您可以在https://docs.oracle.com/javaee/6/tutorial/doc/bnaby.html下找到有关包装的所有必需信息(请注意,这适用于Java EE 6)。

Basicially thats the way to go and i wont be able to help you much more :( 基本上这就是要走的路,我将无法为您提供更多帮助:(

But as requested in the comments i will try to point out some especially important points were linking happens and must be absolutly correct according to the above packaging conventions (i can tell you right away that our JPA-Modules for example are located in the lib-folder as well). 但是,根据评论中的要求,我将尝试指出一些特别重要的地方是发生了链接,并且根据上述包装约定,该点必须绝对正确(例如,我可以马上告诉您我们的JPA模块位于lib-文件夹)。

So if i open one of our (working) EARs i will see the following content inside it: 因此,如果我打开一个(工作中的)EAR耳朵,我将在其中看到以下内容:

  • lib LIB
  • META-INF META-INF
  • our-ejb-part.jar 我们的EJB-part.jar
  • our-website-application.war 我们-网站application.war
  • our-webservice-application.war 我们的Web网页,application.war

Our ejb-part.jar for example does not contain any Java code at all. 例如,我们的ejb-part.jar根本不包含任何Java代码。 It however contains a META-INF folder with descriptors such as ejb-jar.xml and some propertie-files under a properties folder as well. 但是,它包含一个带有描述符的META-INF文件夹,例如ejb-jar.xml并且在properties文件夹下也包含一些特性文件。 It also defines the classpath inside the MANIFEST.MF . 它还在MANIFEST.MF内部定义了类路径。 (I havent worked with JBoss for years - we currently use IBM Websphere hence we have -bnd.xml/-ext.xml deployment descriptors located in the META-INF folder as well ... i am not aware if Jboss needs similar deployment informations). (我已经与JBoss多年合作了-我们目前使用IBM Websphere,因此我们在META-INF文件夹中也有-bnd.xml / -ext.xml部署描述符...我不知道Jboss是否需要类似的部署信息)。 There is nothing more to see here. 这里没有其他可看的了。

Forget about the two Web-Modules for now- you dont seem to have any web-part in the form of a .war file (which itself must follow certain package requirements as defined in the oracle documentation). 现在就忘记这两个Web模块-您似乎没有任何Web部件以.war文件的形式出现(.war文件本身必须遵循oracle文档中定义的某些软件包要求)。

But Note that if you have ANY EJB- or WEB-Modules they must be listed in the application.xml file located in the META-INF file (not the META-INF folder of the ejb but in the META-INF folder of the EAR located on the same level as /lib , /our-ejb-part.jar , etc.). 但是请注意,如果您有任何EJB或WEB模块,则必须将它们列出在位于META-INF文件(不是ejb的META-INF文件夹,而是EAR的META-INF文件夹)中的application.xml文件中与/lib/lib /our-ejb-part.jar等位于同一级别)。 Also note that inside that META-INF directory we again have the two Websphere deployment descriptors as well as a empty MANIFEST.MF). 还要注意,在该META-INF目录中,我们再次具有两个Websphere部署描述符以及一个空MANIFEST.MF)。

Finally we have the lib folder that contains all of our EAR-Dependencies (and most of the Web-Part dependencies) are located at. 最后,我们有一个lib文件夹,其中包含我们所有的EAR依赖项(以及大多数Web部件依赖项)。 That is the location we keep our JPA-, Commons-, Service-, Service-Implementations-, etc. Modules of a component (rather than having them inside the ejb-part.jar ... but i cant consider if this is a good practise). 那是我们保留JPA,Common,Service,ServiceImplementations等的位置。组件的模块(而不是将它们包含在ejb-part.jar ……但是我无法考虑这是否是一个好的做法)。

So comming back to your situation there could be lots of things going wrong - i recommend you add a print-screen of the contents of your final *.ear file rather than the above eclipse view to probably get further advices. 因此,回到您的情况来看,可能有很多地方出了问题-我建议您添加最终* .ear文件内容的打印屏幕,而不是上面的eclipse视图,以获得更多建议。 The main problem of that eclipse view is that at least i dont know how exactly your final .ear file will look like (There is for example only the WEB-INF folder with the application.xml located under EAR Content . 蚀视图的主要问题在于,至少我不知道最终的.ear文件到底是什么样子(例如,只有EAR Content目录中的application.xml位于WEB-INF文件夹中。

Sorry i wont be a help from here on since i dont have any JBoss knowledge (the log may imply whats wrong on a even more detailed level than i can interpret ... i currently just know your EAR likely wont contain the class LotUpdates or it may be there but isnt added to the classpath properly) 抱歉,因为我不具备任何JBoss知识,所以从这里开始我将不会提供任何帮助(日志可能暗示比我能解释的还要详细的级别出了什么问题……我目前仅知道您的EAR可能不会包含LotUpdates类或它可能在那里,但没有正确添加到类路径中)

I did the same with eclipse on Ubuntu. 我在Ubuntu上对eclipse做过同样的事情。 EAR file contain ejb.jar and jpa.jar which jpa.jar is in *.ear/lib/ . EAR文件包含* .ear / lib /中的jpa.jar的ejb.jar和jpa.jar。 Jboss 7 can deployed the ear packed. Jboss 7可以将耳朵打包好。 I think the root cause is jpa classes are built and packaged in jpa.jar, so that ejb.jar can load its. 我认为根本原因是jpa类是在jpa.jar中构建和打包的,因此ejb.jar可以加载它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM