无法在耳朵内访问 EJB jar

Cannot access EJB jar within an ear

我的耳朵结构如下:

XYZ.ear
    |
    |------------- lib
    |-------------META-INF
    |--------------firstEJB.jar
    |--------------app.war

当我尝试部署 XYZ.ear 时,我无法访问 firstEJB.jar 中的 classes。我在尝试部署时遇到以下错误:

15:49:24,583 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.deployment.subunit."XYZ.ear"."app.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."XYZ.ear"."app.war".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of subdeployment "app.war" of deployment "XYZ.ear"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [wildfly-server-8.0.0.Final.jar:8.0.0.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.0.Final.jar:1.2.0.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.0.Final.jar:1.2.0.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_71]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_71]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: com.sial.ecommerce.core.init.DeepInit from [Module "deployment.XYZ.ear.app.war:main" from Service Module Loader]
    at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.checkDeclaredApplicationClassAsServlet(JaxrsScanningProcessor.java:292)
    at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scanWebDeployment(JaxrsScanningProcessor.java:154)
    at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:105)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.0.0.Final.jar:8.0.0.Final]
    ... 5 more
Caused by: java.lang.ClassNotFoundException: com.sial.ecommerce.core.init.DeepInit from [Module "deployment.XYZ.ear.app.war: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]
    at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.checkDeclaredApplicationClassAsServlet(JaxrsScanningProcessor.java:290)

DeepInit class 是 firstEJB.jar 中的 class。

当我尝试在 lib 目录中添加 firstEJB.jar 时,它显示了一些与 beanmanager 相关的问题,因为它包含 ejbs。所以我试着把这个 jar 放在 lib 目录之外,经过这个 link:

https://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly.

我正在使用 build.gradle 构建 EAR.My build.gradle 是:

buildscript {
    repositories {
        mavenCentral(); 
        maven {
            url "https://repository.jboss.org/nexus/content/repositories/releases/"
        }
    }

    configurations {
        compile
        testCompile
        testRuntime
        jacoco
    } 

    dependencies { 
        classpath 'org.ajoberstar:gradle-jacoco:0.3.0'
    }  
}

allprojects {
    group = 'com.sial.ecommerce'
    version = ''


    repositories {
        mavenCentral();
        maven {
            url "https://repository.jboss.org/nexus/content/repositories/releases/"
        }
    }

    apply plugin: 'java'
    apply plugin: 'jacoco';

    apply plugin: 'ear'

    dependencies {
        deploy project(path:':app', configuration: 'archives');
        deploy project(path:':firstEJB', configuration: 'archives');


    }

    ear {
        version = "";

        archiveName ="XYZ.ear";

        appDirName 'EarContent'

        duplicatesStrategy = DuplicatesStrategy.EXCLUDE;
        caseSensitive = true;

        rootSpec.exclude("**/activation-1.1.jar");
        rootSpec.exclude("**/asm*.jar");
        rootSpec.exclude("**/jboss-*.jar");
        rootSpec.exclude("**/org.jacoco*.jar");
        rootSpec.exclude("**/wildfly-*.jar");
        rootSpec.exclude("**/hibernate-*.jar");
        rootSpec.exclude("**/gradle-*.jar");
        rootSpec.exclude("**/cdi-*.jar");
        rootSpec.exclude("**/org.osgi.*.jar");
        rootSpec.exclude("**/serializer-*.jar");
        rootSpec.exclude("**/arquillian-*.jar");
        rootSpec.exclude("**/resteasy-*.jar");
        rootSpec.exclude("**/guava-*.jar");
        rootSpec.exclude("**/jackson-jaxrs-*.jar");
        rootSpec.exclude("**/jackson-core-asl-*.jar");
        rootSpec.exclude("**/jackson-mapper-asl-*.jar");
        rootSpec.exclude("**/reflections-*.jar");
        rootSpec.exclude("**/metrics-core-*.jar");
        rootSpec.exclude("**/servo-core-*.jar");
        rootSpec.exclude("**/aspectjweaver-*.jar");
        rootSpec.exclude("**/javax.json-*.jar");
        rootSpec.exclude("**/jaxrs-api-*.jar");
        rootSpec.exclude("**/javax.mail-*.jar");
        rootSpec.exclude("**/validation-api-*.jar");
        rootSpec.exclude("**/javassist-*.jar");
        rootSpec.exclude("**/dom4j-*.jar");
        rootSpec.exclude("**/annotations-*.jar");
        rootSpec.exclude("**/javax.inject-*.jar");
        rootSpec.exclude("**/xalan-*.jar");
        rootSpec.exclude("**/el-api-*.jar");
        rootSpec.exclude("**/jsr250-api-*.jar");
        rootSpec.exclude("**/xml-apis-*.jar");
        rootSpec.exclude("**/slf4j-api-1.7.6.jar");
    }
}

我在 META-INF 中的 application.xml 看起来像:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" id="Application_ID" version="7">
  <display-name>ABC</display-name>
  <module>
    <web>
      <web-uri>app.war</web-uri>
      <context-root>app</context-root>
    </web>
  </module>
  <module>
      <ejb>myfirstEJB.jar</ejb>
    </module>
</application>

我注意到的另一个问题是,对于部署,服务器正在从以下位置搜索文件:

C:\Apps\wildfly8.0.0.Final\bin目录

ERROR com.sial.ecommerce.core.init.DeepInit - C:\Apps\wildfly-8.0.0.Final\bin\src\test\resources\xml\con\con.json (The system cannot find the path specified)

DEEPInit class 是我的 firstEJB.jar 中的一个 class。

而不是

C:\Apps\wildfly-8.0.0.Final\standalone\deploments 目录(我们耳朵所在的地方).

有人可以帮助我构建和部署合适的耳朵,以便可以访问 firstEJB.jar 中的 classes 吗?

尝试将 wildfly 配置中的 EE 子系统的 "ear-subdeployments-isolated" 属性 设置为 false:

<subsystem xmlns="urn:jboss:domain:ee:1.0" >            
  <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
</subsystem>

如果此设置设置为 true(这是默认的 afaik),那么您必须声明从 war 到 jar 的依赖项:

https://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly

看起来 class com.sial.ecommerce.core.init.DeepInit 正在尝试使用如下代码读取本地资源:

new File(".\src\test\resources\xml\con\con.json");

如果是,请将此代码替换为:

com.sial.ecommerce.core.init.DeepInit.getResource("xml\con\con.json");