无法使用JBoss服务器实例化InitialContext [英] Cannot instantiate InitialContext with JBoss server

查看:140
本文介绍了无法使用JBoss服务器实例化InitialContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个InitialContext,所以我可以向JNDI索要一些企业Java Bean. JBoss运行正常,但是当我运行Java代码时,出现异常.

I'm trying to create a InitialContext so I could ask the JNDI for some enterprise java beans. The JBoss is running fine, but when I run the java code I get an exception.

我正在运行JBoss 7.1

I'm running JBoss 7.1

这是我的代码:

public class Test {

    public static void main(String[] args){
        InitialContext ctx=getInitialContext();
        Object ref=null;
        try {
            ref = ctx.lookup("ParamEJB/remote");
        } catch (NamingException e) {
            System.out.println("Lookup Failed");
            e.printStackTrace();
        }
        Param stub=(Param)PortableRemoteObject.narrow(ref, Param.class);
        int times=stub.getTimes();
        for(int i=0;i<times;i++)
            System.out.println(stub.getMessage());
    }

    public static InitialContext getInitialContext(){
        Hashtable<String,String> h=new Hashtable<String,String>();
        h.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
        h.put("java.naming.provider.url","localhost");
        try {
            return new InitialContext(h);
        } catch (NamingException e) {
            System.out.println("Cannot generate InitialContext");
            e.printStackTrace();
        }
        return null;
    }
    }

启动我的JBoss服务器后,我尝试运行Java代码,并得到以下异常:

And after i start my JBoss server, I try to run the java code and I get this exception:

javax.naming.NoInitialContextException: Cannot instantiate class:     org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException:     org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at client.Test.getInitialContext(Test.java:32)
at client.Test.main(Test.java:13)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)

可能是什么问题?

推荐答案

InitialContext属性不适用于您使用的JBoss版本. 使用JBoss 7,当您从远程客户端调用ejb时,情况发生了很大变化. 此链接可以帮助您正确实例化并使用InitialContex对象确定JNDI条目名称.还将告诉您需要添加到客户端类路径的必要依赖项.

The InitialContext properties are not right for the JBoss version that you are using. With JBoss 7, things have changed considerably when you call a ejb from a remote client. This link can help you to instantiate correctly the InitialContex object and to determine the JNDI entry name. Also will tell you what are the necessary dependencies that need to be added to the client classpath.

这篇关于无法使用JBoss服务器实例化InitialContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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