ClassNotFoundException:org.jboss.naming.remote.client.InitialContextFactory [英] ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory

查看:448
本文介绍了ClassNotFoundException:org.jboss.naming.remote.client.InitialContextFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用环境:


  • WildFly 9.0.2.Final

  • EJB 3.0

  • Ant

  • Eclipse

  • WildFly 9.0.2.Final
  • EJB 3.0
  • Ant
  • Eclipse

Test.jsp 正在调用 Test.java 类的 getDbConnection 方法。

测试.jsp

<%@page import="com.testmodule.pojo.Test"%>
<%
    try{
        System.out.println(" Going to call getDbConnection method of 'Test' class. This 'Test' class shall be "
            + " part of testclient.jar. testclient.jar shall be deployed as a module --- module add --name=testclient --resources=/Downloads/lib/test/testclient.jar");
        System.out.println(" test.jsp shall be present in test.ear...'jboss-deployment-structure.xml' shall be present in "
            + " in META-INF directory of test.ear with entry as -- <dependencies><module name=\"testclient\" export=\"true\" /> </dependencies>");
        System.out.println(" Dont want to put 'jboss-client.jar' in Test.ear-->Test.war-->WEB-INF/lib , As there are multiple ear's which are accessing Test.java class");

        new Test().getDbConnection();
    } catch(Exception e) {
        e.printStackTrace();
    }
%>

Test.java

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://29.86.30.73: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();
        }
    }
}

访问测试时发生以下错误.jsp。

Following error occurred while accessing test.jsp.

10:09:26,536 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]]
10:09:26,537 ERROR [stderr] (default task-1)    at org.jboss.as.naming.InitialContext.getDefaultInitCtx(InitialContext.java:118)
10:09:26,537 ERROR [stderr] (default task-1)    at org.jboss.as.naming.InitialContext.init(InitialContext.java:99)
10:09:26,537 ERROR [stderr] (default task-1)    at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:154)
10:09:26,537 ERROR [stderr] (default task-1)    at org.jboss.as.naming.InitialContext.<init>(InitialContext.java:89)
10:09:26,548 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]
10:09:26,548 ERROR [stderr] (default task-1)    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
10:09:26,548 ERROR [stderr] (default task-1)    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
10:09:26,549 ERROR [stderr] (default task-1)    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
10:09:26,549 ERROR [stderr] (default task-1)    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)

我不想放em> jboss-client.jar 在Test.ear - > Test.war - > WEB-INF / lib中,因为有多个EAR可以访问Test.java 类。

I don't want to put jboss-client.jar in Test.ear --> Test.war --> WEB-INF/lib, as there are multiple EARs which will access Test.java class.

推荐答案

您尝试加载一些本地数据源时,您的JNDI代码用于远程调用。
您可以使用jboss-deployment-structure.xml文件在jboss客户端模块上添加依赖关系。

Your JNDI code is for remote call while you are trying to load some local datasource. You may add a dependency on the jboss client module with a jboss-deployment-structure.xml file.

这篇关于ClassNotFoundException:org.jboss.naming.remote.client.InitialContextFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆