String CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory";
 String CONNECT_URL = "127.0.0.1:4848";
 try {
// jini
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL, CONNECT_URL); //Get a naming context
InitialContext ctx = new javax.naming.InitialContext(env); //Get a reference to the Interest Bean ejb-name
Object ref = ctx.lookup("HelloHome"); //Get a reference from this to the Bean"s Home interface
home = (HelloHome) PortableRemoteObject
.narrow(
ref,
HelloHome.class ); //Create an object from the Home interface
Hello hello  = home.create();
System.out.println( hello.hello() );
          hello.remove(); } catch (Exception ce) {
ce.printStackTrace();
}
另外,你的EJB的JNI name是hellohome?确定?

解决方案 »

  1.   

    应该是JNDI的问题,检查一下你的JNDI的名称
      

  2.   

    谢谢大家,我试试 mofeir(损人专家)的方法
      

  3.   

    jndi问题,确认jndi是否与配置文件中的一致。
      

  4.   

    我刚才试了试mofeir(损人专家)的方法,报找不到org.jnp.interfaces.NamingContextFactory这个类,谁知道这个类在哪个jar里?
      

  5.   

    用mofeir的方法,把org.jnp.interfaces.NamingContextFactory换成com.sun.jndi.fscontext.RefFSContextFactory,你的-Djava.naming.provider.url定义错误,最好指定一个url,如http://localhost/dir/hello.Hello,或者///file:c/hello.Hello
      

  6.   

    com.sun.jndi.fscontext.RefFSContextFactory -Djava.naming.provider.url=file:c\ hello.Hello是用来检索磁盘文件的, 使用 JNDI 一样的接口,同样可能有一个 类似的检索 jar/zip/rar 等压缩包的 JNDI API 提供 JNDI 接口。EJB 使用的不是这个实现方式。org.jnp.interfaces.NamingContextFactory 可能是 JBOSS 上的实现吧?到 jboss 安装路径下找找jar 看里面有没有 (winZip/WinRAR 打开,或者 WinXP 能搜索压缩文件夹)。你说已经部署了一个 EJB ,那就应该知道是谁家的东西,
      

  7.   

    to:oyjdev(探索者) 
    我使用http方式的,报没有这个协议
    to: humanity(很健忘了)
    我是使用sun的appserver部署的,应该使用什么参数啊?