1

为了对多个应用程序可见外部 jar,我通常将外部 jar 放在 JBOSS 5.x 中的 $JBOSS_HOME/server/default/lib 目录中。这些 jar 在 AS 的启动时自动启动。我将如何在 wildfly-9.0.2.Final 中执行此操作。

@SamThankx 的回复但我仍然收到错误,请按照以下结构查看我的场景

  1. test.ear 中存在名为 test.jar 的 jar 存档
  2. 在 test.jar 中有 EJB3 会话 bean java 类。在这个类中有 import stmt as。

    导入 com.oracle.asmc.ejb3.statelesssession.SLE3DecryptLocal;

  3. 上面的包 'com.oracle.asmc.ejb3.statelesssession.SLE3DecryptLocal' 存在于 testclient.jar

注意 - 上面的 testclient.jar 不是 test.ear 的一部分。(我想从多个 EAR 访问这个 testclient.jar)

要部署 test.ear,我已完成以下步骤

  1. ./jboss-cli.sh -c(存在于 bin 目录中)
  2. 模块添加 --name=testclient --resources=~/client_jar/testclient.jar
  3. 我在 jboss-deployment-structure.xml 中添加了以下配置,并在创建 test.ear 时放置在 META-INF 目录中。

    <?xml version="1.0"?>       
       <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
      <deployment>
      <dependencies>
           <module name="testclient" />
      </dependencies>
    </deployment>
    </jboss-deployment-structure>
    
  4. 为了部署 Test.ear 应用程序,访问“ http://127.0.0.1:9990/ ”并遍历链接 Deployments --> Add -->Add Deployment --->FINISH 但仍然出现以下错误。

    12:19:22,439 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) WFLYSRV0027: Starting deployment of "test.ear" (runtime-name: "test.ear")
    12:19:22,602 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0207: Starting subdeployment (runtime-name: "test.jar")
    12:19:22,608 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0207: Starting subdeployment (runtime-name: "test.war")
    12:19:23,524 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) WFLYWELD0003: Processing weld deployment test.ear
    12:19:23,631 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-2) HV000001: Hibernate Validator 5.1.3.Final
    12:19:23,842 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.subunit."test.ear"."test.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."test.ear"."test.jar".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of subdeployment "test.jar" of deployment "test.ear"
      at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:163)
      at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
      at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
     Caused by: java.lang.RuntimeException: WFLYSRV0177: Error getting reflective information for class com.oracle.test.SlsTestBean with ClassLoader ModuleClassLoader for Module "deployment.test.ear.test.jar:main" from Service Module Loader
     at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70)
     at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:57)
     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:156)
    ... 5 more
      Caused by: java.lang.NoClassDefFoundError: com/oracle/asmc/ejb3/statelesssession/SLE3DecryptLocal
     at java.lang.Class.getDeclaredMethods0(Native Method)
     at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
     at java.lang.Class.getDeclaredMethods(Class.java:1975)
     at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:65)
     at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66)
      ... 10 more
      Caused by: java.lang.ClassNotFoundException: com/oracle/asmc/ejb3/statelesssession/SLE3DecryptLocal from [Module "deployment.test.ear.test.jar:main" from Service Module Loader]
     at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
     at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
     at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
     ... 15 more
    

@Sam 谢谢回复

我在 test.jar 的 META-INF 中添加了“jboss-deployment-structure.xml”。

注意 - 是的,我正在从 test.jar 访问“com/oracle/asmc/ejb3/statelesssession/SLE3DecryptLocal”(存在于 testclient.jar 模块中)。

现在我的 test.ear 包含

  1. META-INF/application.xml

  2. 测试战争

  3. test.jar('jboss-deployment-structure.xml' 出现在这个 test.jar 的 META-INF 目录中)

但我仍然收到以下错误。

Caused by: java.lang.NoClassDefFoundError: com.oracle.asmc.ejb3.statelesssession.SLE3DecryptLocal
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:65)
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66)
... 10 more
 Caused by: java.lang.ClassNotFoundException: com.oracle.asmc.ejb3.statelesssession.SLE3DecryptLocal from [Module "deployment.test.ear.test.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
... 15 more
4

1 回答 1

4

WildFly 完全改变了类加载。您可以阅读更多信息 [在]

从 WildFly 8 开始,类加载与以前的 JBoss AS 版本有很大不同。类加载基于 JBoss Modules 项目。与更熟悉的分层类加载环境不同,WildFly 的类加载基于必须定义对其他模块的显式依赖关系的模块。WildFly 中的部署也是模块,并且无法访问在应用服务器的 jar 中定义的类,除非定义了对这些类的显式依赖。

更多信息可以在WildFly 9 文档中找到

基本上,您可以使用共享库添加一个模块,并使您的部署依赖于它。

例如,您可以使用 jboss-cli(位于 bin 文件夹中)添加一个带有 MySQL Connector Java 的模块

module add --name=org.mysql --resources=mysql-connector-java-5.1.31-bin.jar --dependencies=javax.api,javax.transaction.api

然后为了让您的应用程序看到它,您可以添加一个名为的文件,jboss-deployment-structure.xml其中包含以下信息:

<?xml version="1.0"?>

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <dependencies>
            <module name="org.mysql" />
        </dependencies>
    </deployment>
</jboss-deployment-structure>

模块名称必须与您在模块添加命令中指定的名称匹配。

jboss-deployment-structure.xml如果您MANIFEST.MFDependencies部分中添加模块名称,则可以省略该文件

于 2016-01-22T20:57:56.737 回答