【问题标题】:Maven inserts the dependencies into EAR instead of in the moduleMaven 将依赖项插入 EAR 而不是模块中
【发布时间】:2015-03-06 23:36:17
【问题描述】:

我有这个项目https://github.com/AndreaCatania/libreria

它有 3 个模块 "deweb" "decore" "libreriaEar"

模块 libreriaEar 使用 deweb 和 dere 模块创建 EAR 存档 我尝试在模块“decore”中使用 Hibernate,但 maven 没有将依赖项导入“decore”模块,我收到 NoClassFoundException 错误。

如果我检查 ear 存档,我会在其中找到所有依赖项,而不是在模块“decore”中。

生成的 EAR 存档

生成的核心模块(EJB) 怎么了?


编辑 1

主 pom:https://github.com/AndreaCatania/libreria/blob/master/pom.xml


编辑 2

当我将项目部署到 WildFly AS 时出现此错误。

[0m[31m16:01:10,654 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-9) MSC000001: Failed to start service jboss.deployment.subunit."libreriaEar-1.0-SNAPSHOT.ear"."decore-1.0-SNAPSHOT.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."libreriaEar-1.0-SNAPSHOT.ear"."decore-1.0-SNAPSHOT.jar".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of subdeployment "decore-1.0-SNAPSHOT.jar" of deployment "libreriaEar-1.0-SNAPSHOT.ear"
  org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [wildfly-server-8.2.0.Final.jar:8.2.0.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_31]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_31]
        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_31]
    Caused by: java.lang.RuntimeException: JBAS018757: Error getting reflective information for class com.ac.ejbs.SingBean with ClassLoader ModuleClassLoader for Module "deployment.libreriaEar-1.0-SNAPSHOT.ear.decore-1.0-SNAPSHOT.jar:main" from Service Module Loader
        at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:72) [wildfly-server-8.2.0.Final.jar:8.2.0.Final]
        at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:58)
        at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:107)
        at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:92)
        at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:77)
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.2.0.Final.jar:8.2.0.Final]
        ... 5 more
    Caused by: java.lang.NoClassDefFoundError: org/hibernate/service/ServiceRegistry
        at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.8.0_31]
        at java.lang.Class.privateGetDeclaredFields(Class.java:2575) [rt.jar:1.8.0_31]
        at java.lang.Class.getDeclaredFields(Class.java:1908) [rt.jar:1.8.0_31]
        at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57) [wildfly-server-8.2.0.Final.jar:8.2.0.Final]
        at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:68) [wildfly-server-8.2.0.Final.jar:8.2.0.Final]
        ... 10 more
    Caused by: java.lang.ClassNotFoundException: org.hibernate.service.ServiceRegistry from [Module "deployment.libreriaEar-1.0-SNAPSHOT.ear.decore-1.0-SNAPSHOT.jar:main" from Service Module Loader]
        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213) [jboss-modules.jar:1.3.3.Final]
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) [jboss-modules.jar:1.3.3.Final]
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408) [jboss-modules.jar:1.3.3.Final]
        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389) [jboss-modules.jar:1.3.3.Final]
        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134) [jboss-modules.jar:1.3.3.Final]
        ... 15 more

【问题讨论】:

标签: java maven jakarta-ee


【解决方案1】:

您不希望应用程序(您的 EAR)中的所有这些依赖项。它们很可能已经由容器(应用程序服务器)提供。 ejb-module 中的 pom.xml 会提取所有这些依赖项,因此 Maven EAR-plugin 会按要求完成工作。

您需要做的是在 ejb 模块的 pom.xml 中将容器提供的所有依赖项标记为“已提供”。

例如

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.3.8.Final</version>
    <type>jar</type>
    <scope>provided</scope>  
</dependency>

编辑:

由于您使用的是 Wildfly,因此只需导入 API:s 并删除所有这些显式依赖项。

    <dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <scope>provided</scope>
    </dependency>

就像我在评论中所说,使用此页面上的 pom 作为参考,你会没事的:

http://www.mastertheboss.com/jboss-server/wildfly-8/maven-configuration-for-java-ee-7-projects-on-wildfly

【讨论】:

  • 我试过了,但我收到了同样的错误。我已将堆栈跟踪发布到问题中。
  • 按照此处的指南制作适合在 Wildfly 上部署的应用程序:mastertheboss.com/jboss-server/wildfly-8/…
  • 我已按照指南中的说明进行了更改(git 已更新)....但错误仍然存​​在。我希望问题不在 EJB 模块“decore”的 POM 中
  • WAR档案有lib目录,而JAR档案(EJB)没有……这正常吗?
  • 我已经从 pom 中删除了所有依赖项并添加了你说的 API……但现在我无法完全构建……我错过了一些东西……你能在 GIT 上检查项目吗请问?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多