//接上面的 
   //----------------------------------------------------------------------------
    // Methods that use Home interface methods to generate a Remote interface reference
    //----------------------------------------------------------------------------    public SessionBean1 create()
    {
        long startTime = 0;
        if (logging)
        {
            log("Calling create()");
            startTime = System.currentTimeMillis();
        }
        try
        {
            sessionBean1 = sessionBean1Home.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(): " + sessionBean1 + ".");
        }
        return sessionBean1;
    }    public EJBMetaData getEJBMetaData()
    {
        EJBMetaData returnValue = null;        long startTime = 0;
        if (logging)
        {
            log("Calling getEJBMetaData()");
            startTime = System.currentTimeMillis();
        }        try
        {
            returnValue = sessionBean1Home.getEJBMetaData();
            if (logging)
            {
                long endTime = System.currentTimeMillis();
                log("Succeeded: getEJBMetaData()");
                log("Execution time: " + (endTime - startTime) + " ms.");
            }
        }
        catch (Exception e)
        {
            if (logging)
            {
                log("Failed: getEJBMetaData()");
            }
            e.printStackTrace();
        }        if (logging)
        {
            log("Return value from getEJBMetaData(): " + returnValue + ".");
        }
        return returnValue;
    }    public HomeHandle getHomeHandle()
    {
        HomeHandle returnValue = null;        long startTime = 0;
        if (logging)
        {
            log("Calling getHomeHandle()");
            startTime = System.currentTimeMillis();
        }        try
        {
            returnValue = sessionBean1Home.getHomeHandle();
            if (logging)
            {
                long endTime = System.currentTimeMillis();
                log("Succeeded: getHomeHandle()");
                log("Execution time: " + (endTime - startTime) + " ms.");
            }
        }
        catch (Exception e)
        {
            if (logging)
            {
                log("Failed: getHomeHandle()");
            }
            e.printStackTrace();
        }        if (logging)
        {
            log("Return value from getHomeHandle(): " + returnValue + ".");
        }
        return returnValue;
    }    public void remove(Object p0)
    {
        long startTime = 0;
        if (logging)
        {
            log("Calling remove(" + p0 + ")");
            startTime = System.currentTimeMillis();
        }        try
        {
            sessionBean1Home.remove(p0);
            if (logging)
            {
                long endTime = System.currentTimeMillis();
                log("Succeeded: remove(" + p0 + ")");
                log("Execution time: " + (endTime - startTime) + " ms.");
            }
        }
        catch (Exception e)
        {
            if (logging)
            {
                log("Failed: remove(" + p0 + ")");
            }
            e.printStackTrace();
        }
    }    public void remove(Handle p0)
    {
        long startTime = 0;
        if (logging)
        {
            log("Calling remove(" + p0 + ")");
            startTime = System.currentTimeMillis();
        }        try
        {
            sessionBean1Home.remove(p0);
            if (logging)
            {
                long endTime = System.currentTimeMillis();
                log("Succeeded: remove(" + p0 + ")");
                log("Execution time: " + (endTime - startTime) + " ms.");
            }
        }
        catch (Exception e)
        {
            if (logging)
            {
                log("Failed: remove(" + p0 + ")");
            }
            e.printStackTrace();
        }
    }    //----------------------------------------------------------------------------
    // Methods that use Remote interface methods to access data through the bean
    //----------------------------------------------------------------------------    //----------------------------------------------------------------------------
    // 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)
    {
        SessionBean1TestClient1 client = new SessionBean1TestClient1();
        // 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.
    }
}

解决方案 »

  1.   

    出错信息:
    D:\JBuilderX\jdk1.4\bin\javaw -classpath "E:\CODE\WEB\EJB2\classes;D:\jboss-3.2.5\client\concurrent.jar;D:\jboss-3.2.5\client\gnu-regexp.jar;D:\jboss-3.2.5\client\jacorb.jar;D:\jboss-3.2.5\client\jbossall-client.jar;D:\jboss-3.2.5\client\jboss-client.jar;D:\jboss-3.2.5\client\jboss-common-client.jar;D:\jboss-3.2.5\client\jbossha-client.jar;D:\jboss-3.2.5\client\jboss-iiop-client.jar;D:\jboss-3.2.5\client\jboss-j2ee.jar;D:\jboss-3.2.5\client\jboss-jaas.jar;D:\jboss-3.2.5\client\jbossjmx-ant.jar;D:\jboss-3.2.5\client\jbossmq-client.jar;D:\jboss-3.2.5\client\jbossmqha.jar;D:\jboss-3.2.5\client\jboss-net-client.jar;D:\jboss-3.2.5\client\jbosssx-client.jar;D:\jboss-3.2.5\client\jboss-system-client.jar;D:\jboss-3.2.5\client\jcert.jar;D:\jboss-3.2.5\client\jmx-connector-client-factory.jar;D:\jboss-3.2.5\client\jmx-ejb-connector-client.jar;D:\jboss-3.2.5\client\jmx-rmi-connector-client.jar;D:\jboss-3.2.5\client\jnet.jar;D:\jboss-3.2.5\client\jnp-client.jar;D:\jboss-3.2.5\client\jsse.jar;D:\jboss-3.2.5\client\log4j.jar;D:\JBuilderX\lib\j2ee.jar;D:\JBuilderX\jdk1.4\demo\jfc\Java2D\Java2Demo.jar;D:\JBuilderX\jdk1.4\demo\plugin\jfc\Java2D\Java2Demo.jar;D:\JBuilderX\jdk1.4\jre\javaws\javaws.jar;D:\JBuilderX\jdk1.4\jre\lib\charsets.jar;D:\JBuilderX\jdk1.4\jre\lib\ext\dnsns.jar;D:\JBuilderX\jdk1.4\jre\lib\ext\ldapsec.jar;D:\JBuilderX\jdk1.4\jre\lib\ext\localedata.jar;D:\JBuilderX\jdk1.4\jre\lib\ext\sunjce_provider.jar;D:\JBuilderX\jdk1.4\jre\lib\im\indicim.jar;D:\JBuilderX\jdk1.4\jre\lib\im\thaiim.jar;D:\JBuilderX\jdk1.4\jre\lib\jce.jar;D:\JBuilderX\jdk1.4\jre\lib\jsse.jar;D:\JBuilderX\jdk1.4\jre\lib\plugin.jar;D:\JBuilderX\jdk1.4\jre\lib\rt.jar;D:\JBuilderX\jdk1.4\jre\lib\sunrsasign.jar;D:\JBuilderX\jdk1.4\lib\dt.jar;D:\JBuilderX\jdk1.4\lib\htmlconverter.jar;D:\JBuilderX\jdk1.4\lib\tools.jar"  ejb2.SessionBean1TestClient1 
    -- Initializing bean access.log4j:WARN No appenders could be found for logger (org.jnp.interfaces.NamingContext).log4j:WARN Please initialize the log4j system properly.javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1119) at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1196) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:516)-- Failed initializing bean access. at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:509) at javax.naming.InitialContext.lookup(InitialContext.java:347) at ejb2.SessionBean1TestClient1.initialize(SessionBean1TestClient1.java:49) at ejb2.SessionBean1TestClient1.<init>(SessionBean1TestClient1.java:31) at ejb2.SessionBean1TestClient1.main(SessionBean1TestClient1.java:288)Caused by: java.net.SocketTimeoutException: Receive timed out at java.net.PlainDatagramSocketImpl.receive(Native Method) at java.net.DatagramSocket.receive(DatagramSocket.java:711) at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1089) ... 7 more
      

  2.   

    网络有问题?Object ref = context.lookup("SessionBean1");
    试试网络通吗
      

  3.   

    把jboss3.x解压缩后,再在jbuildx中的configure servers把jboss 3.x+上的enable server勾了,再选了home directory的目录,再用jbuildx的向导生成了一个session bean,最后用ejb test client生成测试程序,我一行代码都没写过,都是向导生成的,为什么回报错啊?
      

  4.   

    解决了,我们开启joss服务 汗!