刚刚做了个JBoss入门:报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这样的错,
求解决方案,在此谢过java代码:-------------------------------------------------------package com.sls.ejb3;public interface HelloEJB3 {
public String sayHello(String name);
}-------------------------------------------------------package com.sls.ejb3.impl;import javax.ejb.Remote;
import javax.ejb.Stateless;import com.sls.ejb3.HelloEJB3;@Stateless
@Remote(HelloEJB3.class)
// @Stateless 这个注解可以指定类是个无状态的会话bean
public class HelloEjb3Bean implements HelloEJB3 { @Override
public String sayHello(String name) {
return name + "说:你好,世界....";
}}-------------------------------------------------------
客户端代码:
public static void main(String[] args) {
// Properties props = new Properties();
// props.setProperty("java.namint.jactory.initial",
// "org.jnp.interfaces.NamingContextFactory");
// props.setProperty("java.naming.provider.url", "localhost:1099");
InitialContext ctx;
try {
ctx = new InitialContext();
System.out.println("110" + ctx);
HelloEJB3 helloEJB3 = (HelloEJB3) ctx
.lookup("java:helloEjb3/HelloEjb3Bean/remote");
System.out.println(helloEJB3.getClass().getName());
// System.out.println(helloEJB3.sayHello("尚立帅"));
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}-------------------------------------------------------
jndi.properties代码:java.namint.jactory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099

解决方案 »

  1.   

    HelloEJB3 helloEJB3 = (HelloEJB3) ctx.lookup("java:helloEjb3/HelloEjb3Bean/remote")
    改为
    HelloEJB3 helloEJB3 = (HelloEJB3) ctx.lookup("HelloEjb3Bean/remote")
    试下
      

  2.   

    没搞过Jboss这高级东东呢~~~顶一下
      

  3.   

    HelloEJB3 helloEJB3 = (HelloEJB3) ctx.lookup("java:helloEjb3/HelloEjb3Bean/remote")
    改为
    HelloEJB3 helloEJB3 = (HelloEJB3) ctx.lookup("HelloEjb3Bean/remote")
    也不行啊!
    helloEJB3没值啊!
    我觉得还是ctx.lookup("HelloEjb3Bean/remote")这儿有问题啊!
    求高手赐教!谢谢了
      

  4.   

    你在jboss管理页面看下,你的EJB发布成功没,且名字是什么
      

  5.   

    HelloEjb3.jar
    这是发布后的的名称。
    我用这个也试过但也不行
      

  6.   

    你没理解我意思,任何ejb只要被jboss部署了,都会在jboss管理页面看到,还可以看到该ejb在jndi上的名称,我现在是非常怀疑你的ejb没发布成功
      

  7.   

    http://www.blogjava.net/afei0922/articles/131481.html
    这个帖子应该可以帮助你确定问题
      

  8.   

    HelloEjb3Impl (class: org.jnp.interfaces.NamingContext)
      |   +- remote-com.sls.ejb3.HelloEJB3 (class: Proxy for: com.sls.ejb3.HelloEJB3)
      |   +- remote (class: Proxy for: com.sls.ejb3.HelloEJB3)
    这是管理页面的代码,名称是HelloEjb3Impl,我用这个也不行啊!
      

  9.   

    参考下我的
    package touch.test.client;
    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import touch.portal.interfaces.BeanRemoteInterface;
    public class BeanClient {
    private static Context getJBossInitialContext() {
    Context context = null;
    try {
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    properties.put(Context.PROVIDER_URL, "jnp://ServerTest:1099");
    properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
    context = new InitialContext(properties);
    } catch (NamingException e) {
    System.out.println("Can not connect JBoss Server : ServerTest:1099");
    }
    return context;
    }
    public static void main(String[] args) {
    try {
    Context context = getJBossInitialContext();
    Object object = context.lookup("PortalBean/remote-touch.portal.interfaces.BeanRemoteInterface");
    BeanRemoteInterface portalBean = (BeanRemoteInterface) object;
    String strRtn = portalBean.getResult("{\"SERVCOM\":\"DutAddQueue\",\"SERVPARAM\":{},\"SERVMETHOD\":\"qry\"}");
    System.out.println(strRtn);
    } catch (Exception e) {
    e.printStackTrace();
    System.out.println(e.getMessage());
    }
    }
    }
      

  10.   

    Object object = context.lookup("PortalBean/remote-touch.portal.interfaces.BeanRemoteInterface");
     BeanRemoteInterface portalBean = (BeanRemoteInterfae) object
    我的主要是object这个对象出不来啊!
    我很是纠结,
      

  11.   

    首先jboss的Properties要设置其次我的Bean是这样的
    package touch.portal.interfaces;
    import javax.ejb.Remote;
    @Remote
    public interface BeanRemoteInterface {
    public String getResult(String strArg);
    }
      

  12.   

    JBoss的话这两行是固定的。properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      

  13.   

    Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");try {
          Context  ctx = new InitialContext(jndiProperties);
          System.out.println("110" + ctx);
          HelloEJB3 helloEJB3 = (HelloEJB3) 
          ctx.lookup("java:/你的项目名/HelloEjb3Bean!com.sls.ejb3.HelloEjb3");
          System.out.println(helloEJB3.getClass().getName());
         // System.out.println(helloEJB3.sayHello("尚立帅"));
    } catch (NamingException e) {
    // TODO Auto-generated catch block
        e.printStackTrace();
    }在客户端src目录新建个jboss-ejb-client.properties里面代码
    remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=falseremote.connections=defaultremote.connection.default.host=localhostremote.connection.default.port = 4447remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false