【问题标题】:java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactoryjava.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory
【发布时间】:2024-01-05 15:09:01
【问题描述】:

我正在将 jboss-4.0.4.GA 移动到 wildfly-8.1.0.Final。在部署我的 EAR 时出现以下错误:

2014-07-10 17:09:44,900 错误 [stderr](默认任务 1) javax.naming.NamingException:JBAS011843:实例化失败 初始上下文工厂 来自类加载器的 org.jboss.naming.remote.client.InitialContextFactory 模块的 ModuleClassLoader 服务模块中的“deployment.wildfly.ear.wildfly-war.war:main” 加载程序 [根异常是 java.lang.ClassNotFoundException: [模块中的 org.jboss.naming.remote.client.InitialContextFactory 服务模块中的“deployment.wildfly.ear.wildfly-war.war:main” 加载器]]

我的代码:

Properties appProp = new Properties();
appProp.put(Context.INITIAL_CONTEXT_FACTORY, CGProperties.initial_context_factory);
appProp.put(Context.PROVIDER_URL, CGProperties.provider_url);
appProp.put("java.naming.rmi.security.manager", "yes");
appProp.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");
appProp.put("jboss.naming.client.ejb.context","true");
context = new InitialContext(appProp);
//context = new InitialContext();

if(serverName.equalsIgnoreCase("JBOSS")) {
    ds = (javax.sql.DataSource) context.lookup(CGProperties.dsName);
    reportDS=(javax.sql.DataSource) context.lookup(CGProperties.reportdsName);
}

请帮我解决这个错误。

【问题讨论】:

  • 您能否发布您在项目中添加的 jar 列表。检查是否添加了 jboss-client jar。这是必需的。
  • 感谢您的回复 Neeraj :) 我在 wildfly-8.1.0.Final\bin\client 中有 jboss-client.jar。如何将此 jar 全局 y 添加到我的应用程序中

标签: java class jboss wildfly-8


【解决方案1】:

需要添加 jboss-client.jar 或包含相应的 WildFly 模块。

正如here 的回答,standalone-full.xml 中的以下配置可以解决问题:

    <subsystem xmlns="urn:jboss:domain:ee:4.0"><!-- ee:2.0  in WildFly 8 -->
                <global-modules>
                    <module name="org.jboss.remote-naming"/>
                </global-modules>
...

允许在另一个 WildFly 服务器上查找远程连接。

【讨论】: