Topic: 调试EJB遇到一点问题,大家看看

  Print this page

1.调试EJB遇到一点问题,大家看看 Copy to clipboard
Posted by: dingwm
Posted on: 2005-05-07 12:22

MYECLIPSE+JBOSS4
写了个EJB
测试时遇到问题 请各位大侠看看
客户端代码:
/*
* Created on 2005-5-6
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.bjb.helloworld.test;
import javax.naming.Context;
import javax.naming.InitialContext;
import com.bjb.helloworld.ejb.*;
import com.bjb.helloworld.interfaces.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import org.jnp.interfaces.NamingContextFactory;
/**
* @author cclx
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class HelloTestClient {

  public static void main(String[] args) throws Exception {
    Context ctx=getInitialContext();
    Object obj=ctx.lookup(HelloWorldHome.JNDI_NAME);
    HelloWorldHome helloworldhome=(HelloWorldHome)PortableRemoteObject.narrow
    (obj,HelloWorldHome.class);
    HelloWorld helloworld=helloworldhome.create();
    System.out.println(helloworld.helloWorld());
  }
  private static Context getInitialContext() throws Exception{
    String url="t3://127.0.0.1:7001";
    String user="cclx";
    String password="cclx";
    Properties properties=null;
    
    properties=new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY,
        "org.jnp.interfaces.NamingContextFactory");
    properties.put(Context.PROVIDER_URL,url);
    if(user!=null){
      properties.put(Context.SECURITY_PRINCIPAL,user);
      properties.put(Context.SECURITY_CREDENTIALS,
          password==null? "" : password);
    }
    return new InitialContext(properties);
  }
}

错误
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(NamingManager.java:652)
  at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
  at javax.naming.InitialContext.init(InitialContext.java:219)
  at javax.naming.InitialContext.<init>(InitialContext.java:195)
  at com.bjb.helloworld.test.HelloTestClient.getInitialContext(HelloTestClient.java:45)
  at com.bjb.helloworld.test.HelloTestClient.main(HelloTestClient.java:23)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
  at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:219)
  at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
  at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
  ... 5 more
Exception in thread "main"

2.Re:调试EJB遇到一点问题,大家看看 [Re: dingwm] Copy to clipboard
Posted by: wangaman
Posted on: 2005-05-09 13:43

它的提示信息是找不到org.jnp.interfaces.NamingContextFactory类,只需将该文件所在的jar包加入环境变量的classpath下即可!

3.Re:调试EJB遇到一点问题,大家看看 [Re: dingwm] Copy to clipboard
Posted by: dingwm
Posted on: 2005-05-09 15:06

解决了

非常感谢 :)


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923