EJB3.0异常总结--- Need to specify class name in environment or system property,

来源:互联网 发布:web即时通讯源码 编辑:程序博客网 时间:2024/05/20 02:23
异常:
 Need to specify class name in environment or system property, or    


as an applet parameter, or in an application resource file:     


java.naming.factory.initial
  原因:
  1.没有写入jndi.properties.
  2.Need to specify class name in environment or system property. 的 
   意思就是找不到你的EJB环境变量. 换句话说就是你的客户在使用lookup   
   的时候. context没有设置对.
  3.Need to specify class name in environment or system property, or 
    as an applet parameter, or in an application resource file:      
    java.naming.factory.initial
     使用的是代码InitialContext     
     ctx=new InitialContext(props);的方式,不存在jndi配置文件不对的问 
    题,最后想起之前一个教程里的一句命名空间的话,于是登录jboss控制  
    台,找到部署的ejb,前面一个java提醒鸟我,将代码里lookup中参数前  
    面加上java:,搞定。
  
 public class EjbClient {  
    public static void main(String[] args) {  
        Properties props=new Properties();  
        props.setProperty


("java.naming.factroy.initial","org.jnp.interfaces.NamingContextFact


ory");  
        props.setProperty


("java.naming.provider.url","localhost:1099");//或者


jnp://localhost...也可  
        props.setProperty("java.naming.factory.url.pkgs", 


"org.jboss.naming:org.jnp.interfaces");//此行必须有  
        try{  
            InitialContext ctx=new InitialContext(props);  
            HelloWorld helloworld=(HelloWorld)ctx.lookup


("java:HelloWorldBean/remote");//前面的java是关键  
            System.out.println(helloworld.sayHello("jack"));  
        }catch(NamingException e){  
            System.out.println("error:"+e.getMessage());  
        }  
    }  
}  
原创粉丝点击