FirSesBean代码:
package seslesspro;import javax.ejb.*;public class FirSesBean implements SessionBean {
  SessionContext sessionContext;
  public void ejbCreate() throws CreateException {
    /**@todo Complete this method*/
  }
  public void ejbRemove() {
    /**@todo Complete this method*/
  }
  public void ejbActivate() {
    /**@todo Complete this method*/
  }
  public void ejbPassivate() {
    /**@todo Complete this method*/
  }
  public void setSessionContext(SessionContext sessionContext) {
    this.sessionContext = sessionContext;
  }
  public String getName() {
    /**@todo Complete this method*/
    return "Testing  name Successful!"; 
  }
}

解决方案 »

  1.   

    FirSesTestClient1代码:package seslesspro;import javax.naming.*;
    import javax.rmi.PortableRemoteObject;public class FirSesTestClient1 extends Object {
      private static final String ERROR_NULL_REMOTE = "Remote interface reference is null.  It must be created by calling one of the Home interface methods first.";
      private static final int MAX_OUTPUT_LINE_LENGTH = 100;
      private boolean logging = true;
      private FirSesHome firSesHome = null;
      private FirSes firSes = null;  //Construct the EJB test client
      public FirSesTestClient1() {
        initialize();
      }  public void initialize() {
        long startTime = 0;
        if (logging) {
          log("Initializing bean access.");
          startTime = System.currentTimeMillis();
        }    try {
          //get naming context
          Context context = getJBossInitialContext();      //look up jndi name
          Object ref = context.lookup("FirSes");
          //look up jndi name and cast to Home interface
          firSesHome = (FirSesHome) PortableRemoteObject.narrow(ref, FirSesHome.class);
          if (logging) {
            long endTime = System.currentTimeMillis();
            log("Succeeded initializing local bean access through Local Home interface.");
            log("Execution time: " + (endTime - startTime) + " ms.");
          }
        }
        catch(Exception e) {
          if (logging) {
            log("Failed initializing bean access.");
          }
          e.printStackTrace();
        }
      }
      private javax.naming.Context getJBossInitialContext() throws NamingException {
        java.util.Hashtable JNDIParm = new java.util.Hashtable();
        JNDIParm.put(Context.PROVIDER_URL, "localhost");
        JNDIParm.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        return new InitialContext(JNDIParm);
      }
      //----------------------------------------------------------------------------
      // Methods that use Home interface methods to generate a Remote interface reference
      //----------------------------------------------------------------------------  public FirSes create() {
        long startTime = 0;
        if (logging) {
          log("Calling create()");
          startTime = System.currentTimeMillis();
        }
        try {
          firSes = firSesHome.create();
          if (logging) {
            long endTime = System.currentTimeMillis();
            log("Succeeded: create()");
            log("Execution time: " + (endTime - startTime) + " ms.");
          }
        }
        catch(Exception e) {
          if (logging) {
            log("Failed: create()");
          }
          e.printStackTrace();
        }    if (logging) {
          log("Return value from create(): " + firSes + ".");
        }
        return firSes;
      }  //----------------------------------------------------------------------------
      // Methods that use Remote interface methods to access data through the bean
      //----------------------------------------------------------------------------  public String getName() {
        String returnValue = "";    if (firSes == null) {
          System.out.println("Error in getName(): " + ERROR_NULL_REMOTE);
          return returnValue;
        }    long startTime = 0;
        if (logging) {
          log("Calling getName()");
          startTime = System.currentTimeMillis();
        }    try {
          returnValue = firSes.getName();
          if (logging) {
            long endTime = System.currentTimeMillis();
            log("Succeeded: getName()");
            log("Execution time: " + (endTime - startTime) + " ms.");
          }
        }
        catch(Exception e) {
          if (logging) {
            log("Failed: getName()");
          }
          e.printStackTrace();
        }    if (logging) {
          log("Return value from getName(): " + returnValue + ".");
        }
        return returnValue;
      }  //----------------------------------------------------------------------------
      // Utility Methods
      //----------------------------------------------------------------------------  private void log(String message) {
        if (message == null) {
          System.out.println("-- null");
          return ;
        }
        if (message.length() > MAX_OUTPUT_LINE_LENGTH) {
          System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");
        }
        else {
          System.out.println("-- " + message);
        }
      }
      //Main method  public static void main(String[] args) {
        FirSesTestClient1 client = new FirSesTestClient1();
        // Use the client object to call one of the Home interface wrappers
        // above, to create a Remote interface reference to the bean.
        // If the return value is of the Remote interface type, you can use it
        // to access the remote interface methods.  You can also just use the
        // client object to call the Remote interface wrappers.    try {
          client.create();
          String name = client.getName();
          System.out.println("Name from the Test Client = " + name);
        }
        catch (Exception ex) { }  }
    }
      

  2.   

    1、错误是什么?
    2、你的jndi怎么配置的?
    3、你发布后jboss状态正确吗4、建议使用servlet测试
      

  3.   

    出错如下:
    -- Initializing bean access.
    javax.naming.CommunicationException: Receive timed out.  Root exception is java.net.SocketTimeoutException: Receive timed out
    at java.net.PlainDatagramSocketImpl.receive(Native Method)
    at java.net.DatagramSocket.receive(DatagramSocket.java:671)
    at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:953)-- Failed initializing bean access.
    at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1040)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:450)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:443)
    at javax.naming.InitialContext.lookup(InitialContext.java:347)
    at seslesspro.FirSesTestClient1.initialize(FirSesTestClient1.java:30)
    at seslesspro.FirSesTestClient1.<init>(FirSesTestClient1.java:15)
    at seslesspro.FirSesTestClient1.main(FirSesTestClient1.java:143)
    -- Calling create()
    java.lang.NullPointerException
    at seslesspro.FirSesTestClient1.create(FirSesTestClient1.java:65)
    at seslesspro.FirSesTestClient1.main(FirSesTestClient1.java:151)
    -- Failed: create()
    -- Return value from create(): null.
    Error in getName(): Remote interface reference is null.  It must be created by calling one of the Home interface methods first.
    Name from the Test Client = 
      

  4.   

    to:accesine960(Stoney) 
    非常感谢!
    jndi需要配置吗?怎么配置?配置哪个文件?或其它!
      

  5.   

    你的EJB容器启动了吗?
    Initializing bean access.
    初始化的时候就出错了,可能是EJB容器的问题吧。容器启动后在,jb8左边的项目列表中找到XXXX.jar,右键部署,成功部署后再run client
    一切OK
      

  6.   

    to:xiaokang520(Nova) 已经部署,没出现异常,非常感谢!debug 发现FirSesTestClient1//look up jndi name开始出错
    Object ref = context.lookup("FirSes");
    //look up jndi name and cast to Home interface
    firSesHome = (FirSesHome) PortableRemoteObject.narrow(ref, FirSesHome.class);用servlet测试,输出
    FirSes not bound初步确定是jndi问题,Home JNDI name 设置为:FirSes
      

  7.   

    写个jndi.properties
    内容
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.provider.url=localhost这些是要根据具体的容器来改的
      

  8.   

    当然你的jndi.properties
    要在你class路径里
      

  9.   

    jndi的配置通常都在classpath底下的一个jndi.properties文件里,内容如下:
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.provider.url=localhost:1099
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces这个jndi.properties文件在jboss中client目录下的jbossjmx-ant.jar文件里,通常jboss的缺省端口号是1099,所以必须在jndi.properties里将java.naming.provider.url配置成和你访问的jboss服务匹配的url。如果觉得改jndi.properties不方便的话,建议在你的client程序里的initialize()函数中的  Object ref = context.lookup("FirSes"); 语句之前加上如下代码:
    System.setProperty("java.naming.factory.initial", 
    "org.jnp.interfaces.NamingContextFactory");
    System.setProperty("java.naming.provider.url", "localhost:1099");
      

  10.   

    看看你的JBoss.xml里的JNDI-NAME,是否和"FirSes"一致。
      

  11.   

    to:flying_bird(飞翔鸟) & shaomickey(不够刺激)  非常感谢!!!!我client程序run参数的VM parameters已经设置为:
    -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.provider.url=localhost:1099 -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    没有设置Application parameters我测试了,按你们的方法,出现的错误一样!
    太打击学习积极性了!!!我坚持!
      

  12.   

    jboss.xml为:<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE jboss PUBLIC '-//JBoss//DTD JBOSS 3.0//EN' 'http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd'>
    <jboss>
        <enterprise-beans>
            <session>
                <ejb-name>FirSes</ejb-name>
                <jndi-name>FirSes</jndi-name>
            </session>
        </enterprise-beans>
    </jboss>ejb-jar.xml为:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
        <enterprise-beans>
            <session>
                <display-name>FirSes</display-name>
                <ejb-name>FirSes</ejb-name>
                <home>seslesspro.FirSesHome</home>
                <remote>seslesspro.FirSes</remote>
                <ejb-class>seslesspro.FirSesBean</ejb-class>
                <session-type>Stateless</session-type>
                <transaction-type>Container</transaction-type>
            </session>
        </enterprise-beans>
        <assembly-descriptor>
            <container-transaction>
                <method>
                    <ejb-name>FirSes</ejb-name>
                    <method-name>*</method-name>
                </method>
                <trans-attribute>Required</trans-attribute>
            </container-transaction>
        </assembly-descriptor>
    </ejb-jar>
      

  13.   

    我执行了,没有错误..
    很显然是你环境的问题...估计你的jndi还是没搞定..如果可以的话,你可以手动在控制台下进行编译,打包,发布,然后运行test..
    这样你或许更清楚你哪些包或环境不对.
      

  14.   

    to :AlanChu(找个女人还是养条狗)
    http://mattkelli.com/tech/jboss/jbuilder7/
      

  15.   

    to:shaomickey(不够刺激) 
    我已经看了,thanks为什么看不到1099是激活的?JNDI还能用吗?
      

  16.   

    1099没有被激活,应该不会吧!jobss运行起来之后,如果你是用的wingdows2000的话,用netstat -na 命令查看一下,1099端口处于LISTENING状态,说明它正在被占用。
      

  17.   

    非常感谢各位的讨论,解决困扰我2天的问题,很简单,
    我有点不好意思说,是我的jboss没启动。我一直以为直接点击client->右键->run using "client",
    jboss就会在JB8里启动运行,其它相关的服务也会启动,现在
    发现我错了。还好发现JNDI服务没启动,同时shaomickey(不够刺激)
    提醒了我 ,在此非常感谢。
      

  18.   

    weblogic就可以做到,jboss肯定能,但不知怎么配置?
      

  19.   

    to: AlanChu(找个女人还是养条狗)
    也可以在jbuilder中运行jboss啊,上次给你的网址里说得很详细,自己看一看吧!!!!
    http://mattkelli.com/tech/jboss/jbuilder7/老大,我是这个论坛的新手,今天忙了一上午了,头昏眼花,有么有给分啊??!!!
    呵呵~~~~~!!!
      

  20.   

    我问一下,虽然贴主给了分我,但是为什么我的分值还是没有变化啊 可以分:780 总信誉分:100 。我是greenhand , 请各位大虾指教!!谢谢了!!!