WFLYNAM0027:ClassNotFoundException:org.jboss.naming.remote.client.InitialContextFactory

时间:2016-04-06 03:57:11

标签: jboss ejb ejb-3.0 wildfly

Enviornment-wildfly-9.0.2.Final,EJB 3.0

尝试连接Test.java类(在wildfly-9.0.2.Final@machine-A上部署为模块)时发生以下错误,在机器B(291.861.301.732)的jboss上部署了EJB whilch。

17:02:46,666 ERROR [stderr] (default task-1) javax.naming.NamingException: WFLYNAM0027: Failed instantiate InitialContextFactory org.jboss.naming.remote.client.InitialContextFactory from classloader ModuleClassLoader for Module "deployment.test.ear.test.war:main" from Service Module Loader [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory from [Module "deployment.test.ear.test.war:main" from Service Module Loader]]
17:02:46,667 ERROR [stderr] (default task-1)    at org.jboss.as.naming.InitialContext.getDefaultInitCtx(InitialContext.java:118)
17:02:46,667 ERROR [stderr] (default task-1)    at org.jboss.as.naming.InitialContext.init(InitialContext.java:99)
17:02:46,670 ERROR [stderr] (default task-1)    at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:154)
17:02:46,670 ERROR [stderr] (default task-1)    at org.jboss.as.naming.InitialContext.<init>(InitialContext.java:89)
17:02:46,670 ERROR [stderr] (default task-1)    at org.jboss.as.naming.InitialContextFactory.getInitialContext(InitialContextFactory.java:43)
17:02:46,687 ERROR [stderr] (default task-1) Caused by: java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory from [Module "deployment.test.ear.test.war:main" from Service Module Loader]
17:02:46,688 ERROR [stderr] (default task-1)    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
17:02:46,688 ERROR [stderr] (default task-1)    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
17:02:46,688 ERROR [stderr] (default task-1)    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
17:02:46,688 ERROR [stderr] (default task-1)    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
17:02:46,688 ERROR [stderr] (default task-1)    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)

test.java类存在于testclient.jar&amp; testclient.jar已使用命令

作为模块进行了解析
module add --name=testclient --resources=/Downloads/lib/test/client/testclient.jar --dependencies=javax.api

Test.java类

package com.testmodule.pojo;

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;

public class Test { 
public void getDbConnection(){
    try{
        Properties jndiProps = new Properties();
        jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
        jndiProps.put(Context.PROVIDER_URL,"remote://291.861.301.732:4447");
        jndiProps.put(Context.SECURITY_PRINCIPAL, "testuser");
        jndiProps.put(Context.SECURITY_CREDENTIALS, "testpassword");
        jndiProps.put("jboss.naming.client.ejb.context", true);
        Context context = new InitialContext(jndiProps);
    }
    catch(Exception e){e.printStackTrace();}
}}

为什么会出现这个错误,对于org.jboss.naming.remote.client.InitialContextFactory&#39;的可见性。到testclient.jar,我应该在部署testclient.jar作为模块时添加更多依赖项(目前只有javax.api)吗?或任何其他导致错误的问题? Class&#39; org.jboss.naming.remote.client.InitialContextFactory&#39;也出现在$ WILDFLY_HOME / bin / client / jboss-client.jar

注意 - 291.861.301.732是远程系统ip,在jboss上部署了ejb。 ,这个ejb使用JNDI从Test.java(远程客户端)调用。

wildfly-9.0.2.Final中没有jnp(在JBOSS 5.x中),所以我替换了属性&#34; org.jnp.interfaces.NamingContextFactory&#34;重视org.jboss.naming.remote.client.InitialContextFactory&#34;。为什么还会发生错误?

在收到评论后添加了以下内容&#39;尝试将jboss-client.jar放在运行时路径中,作为WEB-INF / lib的一部分可能&#39;作者:Sampada Wagde&#39;

我无法理解,在这个scenarion test.jsp(存在于test.ear - &gt; test.war - &gt; test.jsp)文件中调用了函数getDbConnection的Test.java文件。 Test.java文件存在于testclient.jar中,此testclient.jar已作为模块部署。 根据你的建议,当我把jboss-client.jar&#39;在test.ear - &gt; test.war - &gt; WEB-INF - &gt; lib中,问题解决了,现在访问时 application&#39; org.jboss.naming.remote.client.InitialContextFactory&#39;没有发生ClassNotFound异常...... 但是我的问题是有多个war文件(例如..test.war,test1.war,test2.war)并且每个war文件都在访问Test.java文件(存在于testclient.jar中),所以我必须把&#39; jboss-client.jar&#39;每个战争档案的WEB-INF / lib中的文件。对我来说这将是非常复杂的,还有其他方法吗?,其次如何通过将jboss-client.jar&#39;这个问题解决?进入WEB-INF / lib direcory,作为&#39; org.jboss.naming.remote.client.InitialContextFactory&#39;存在于testclient.jar中(不在test.ear - &gt; test.war中)。

在收到回复之后添加了以下内容&#39;服务器在运行时需要jboss-client.jar ...&#39;作者:Sampada Wagde&#39;

我也尝试了以下步骤 1.通过放置jboss-deployment-structure.xml&#39;在test.ear中 - &gt; META-INF - &gt; jboss-deployment-structure.xml

<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<deployment>
    <dependencies>
        <module name="testclient" export="true" />
        <module name="jboss-client" export="true" />
    </dependencies>
</deployment>

  1. 将模块名称部署为

    module add --name=jboss-client --resources=/Downloads/wildfly-9.0.2.Final/bin/client/jboss-client.jar
    
  2. 但仍然发生以下错误。

    14:14:34,376 WARN  [org.jboss.modules] (default task-1) Failed to define class org.jboss.naming.remote.client.InitialContextFactory in Module "jboss-client:main" from local module loader @707f7052 (finder: local module finder @11028347 (roots: /Downloads/wildfly-9.0.2.Final/modules,/Downloads/wildfly-9.0.2.Final/modules/system/layers/base)): java.lang.LinkageError: Failed to link org/jboss/naming/remote/client/InitialContextFactory (Module "jboss-client:main" from local module loader @707f7052 (finder: local module finder @11028347 (roots: /Downloads/wildfly-9.0.2.Final/modules,/Downloads/wildfly-9.0.2.Final/modules/system/layers/base)))
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:437)
    at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:269)
    at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:77)
    at org.jboss.modules.Module.loadModuleClass(Module.java:560)
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)
    Caused by: java.lang.NoClassDefFoundError: javax/naming/spi/InitialContextFactory
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:353)
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:432)
    Caused by: java.lang.ClassNotFoundException: javax.naming.spi.InitialContextFactory from [Module "jboss-client:main" from local module loader @707f7052 (finder: local module finder @11028347 (roots: /Downloads/wildfly-9.0.2.Final/modules,/Downloads/wildfly-9.0.2.Final/modules/system/layers/base))]
    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)
    14:14:34,391 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /test/test.jsp: javax.servlet.ServletException: java.lang.LinkageError: Failed to link org/jboss/naming/remote/client/InitialContextFactory (Module "jboss-client:main" from local module loader @707f7052 (finder: local module finder @11028347 (roots: /Downloads/wildfly-9.0.2.Final/modules,/Downloads/wildfly-9.0.2.Final/modules/system/layers/base)))
    at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:777)
    at org.apache.jsp.test_jsp._jspService(test_jsp.java:85)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    Caused by: java.lang.LinkageError: Failed to link org/jboss/naming/remote/client/InitialContextFactory (Module "jboss-client:main" from local module loader @707f7052 (finder: local module finder @11028347 (roots: /Downloads/wildfly-9.0.2.Final/modules,/Downloads/wildfly-9.0.2.Final/modules/system/layers/base)))
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:437)
    at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:269)
    at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:77)
    at org.jboss.modules.Module.loadModuleClass(Module.java:560)
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)
    Caused by: java.lang.NoClassDefFoundError: javax/naming/spi/InitialContextFactory
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:353)
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:432)
    Caused by: java.lang.ClassNotFoundException: javax.naming.spi.InitialContextFactory from [Module "jboss-client:main" from local module loader @707f7052 (finder: local module finder @11028347 (roots: /Downloads/wildfly-9.0.2.Final/modules,/Downloads/wildfly-9.0.2.Final/modules/system/layers/base))]
    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)
    

2 个答案:

答案 0 :(得分:2)

服务器在运行时需要jboss-client.jar。有几种方法可以为JBoss服务器提供jar -

  1. 在MANIFEST.MF中包含jar(这通常用于您自己的应用程序罐)
  2. 在WEB-INF / lib中包含jar - 如果jar特定于给定的Web项目或WAR
  3. 在模块类加载器中包含jar,并通过jboss-deploymet-structure.xml将其提供给Web项目。当有多个WARS并且其中一些(不是全部)需要罐子时,这样做。
  4. 在模块类加载器中包含jar,并通过standalone.xml中的全局模块将其提供给服务器。当服务器上部署的所有应用程序都引用了jar时,就会完成此操作。
  5. 有关JBoss模块的详细信息,请参阅此链接 - https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7

    关于如何将jboss-client.jar放入WAR而不是testclient.jar解决问题的问题,答案是一样的 - 这就是类加载的工作方式。

答案 1 :(得分:1)

你需要让你自己的模块依赖于一个不仅包含jboss-client jar的模块,还包含jboss-client的所有依赖项,这可能只是其他模块或其他jar。它缺少的第一个类是javax / naming / spi / InitialContextFactory,所以编辑jboss-client模块的module.xml以依赖于javax.api