看看你的lookup()方法中jndi-name与JBoss.xml中的jndi-name是否一致。

解决方案 »

  1.   

    是一样的,下面是我的客户端程序 InterestClient.java
    import javax.naming.*;
    import com.web_tomorrow.interest.*;
    import java.util.Hashtable;
    import java.util.*;
    import javax.rmi.PortableRemoteObject; 
    import com.web_tomorrow.interest.*; /**
    This simple application tests the `Interest' Enterprise JavaBean which is
    implemented in the package `com.web_tomorrow.interest'. For this to work, the
    Bean must be deployed on an EJB server.
    <p>
    <b>IMPORTANT</b> If you want to test this in a real client-server
    configuration, this class goes on the client; the URL of the naming provider
    specifed in the class must be changed from `localhost:1099' to the URL of the
    naming service on the server
    */class InterestClient
    {
    /**
    This method does all the work. It creates an instance of the Interest EJB on
    the EJB server, and calls its `calculateCompoundInterest()' method, then prints
    the result of the calculation.
    */
    public static void main(String[] args)
    {
    // Set up the naming provider; this may not always be necessary, depending
    // on how your Java system is configured.
    /*
    System.setProperty("java.naming.factory.initial", 
    "org.jnp.interfaces.NamingContextFactory");
    System.setProperty("java.naming.provider.url", 
    "localhost:1099");
    */
    //Properties p = new Properties();
    //p.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
    //p.put("javax.naming.provider.url","iipo://localhost:1099");
    java.util.Hashtable JNDIParm = new java.util.Hashtable();
    JNDIParm.put(Context.PROVIDER_URL, "localhost");
        JNDIParm.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    // Enclosing the whole process in a single `try' block is not an ideal way
    // to do exception handling, but I don't want to clutter the program up
    // with catch blocks
    try
    {
    // Get a naming context
        InitialContext jndiContext = new InitialContext(JNDIParm);
    System.out.println("Got context"); // Get a reference to the Interest Bean
    Object ref  = jndiContext.lookup("interest/Interest");
    System.out.println("Got reference"); // Get a reference from this to the Bean's Home interface
    InterestHome home = (InterestHome) 
    PortableRemoteObject.narrow (ref, InterestHome.class); // Create an Interest object from the Home interface
    Interest interest = home.create();

    // call the calculateCompoundInterest() method to do the calculation
    System.out.println 
    ("Interest on 1000 units, at 10% per period, compounded over 2 periods is:");
    System.out.println (interest.calculateCompoundInterest (1000, 0.10, 2));
    }
    catch(Exception e)
    {
    System.out.println(e.toString());
    }
    }
    }
      

  2.   

    你的JNDIParm不对吧?用这个试试:
        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);
      }
      

  3.   

    在classpath里加入jar包:jbossall-client.jar