正在学EJB,使用的是Netbeans。程序源代码:
package com.wiley.compBooks.chapter3.sessionBean;
import javax.ejb.*;
/**
 * This is the bean class for the HelloBean enterprise bean.
 * Created 2006-10-9 20:41:00
 * @author chen
 */
public class HelloBean implements SessionBean, HelloLocalBusiness {
    private SessionContext context;
    
    // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click the + sign on the left to edit the code.">
    // TODO Add code to acquire and use other enterprise resources (DataSource, JMS, enterprise bean, Web services)
    // TODO Add business methods or web service operations
    /**
     * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
     */
    public void setSessionContext(SessionContext aContext) {
        context = aContext;
    }
    
    /**
     * @see javax.ejb.SessionBean#ejbActivate()
     */
    public void ejbActivate() {
        
    }
    
    /**
     * @see javax.ejb.SessionBean#ejbPassivate()
     */
    public void ejbPassivate() {
        
    }
    
    /**
     * @see javax.ejb.SessionBean#ejbRemove()
     */
    public void ejbRemove() {
        
    }
    // </editor-fold>
    
    /**
     * See section 7.10.3 of the EJB 2.0 specification
     * See section 7.11.3 of the EJB 2.1 specification
     */
    public void ejbCreate() {
        // TODO implement ejbCreate if necessary, acquire resources
        // This method has access to the JNDI context so resource aquisition
        // spanning all methods can be performed here such as home interfaces
        // and data sources.
    }
      
    // Add business logic below. (Right-click in editor and choose
    // "EJB Methods > Add Business Method" or "Web Service > Add Operation")    public String hello() {
        return "Hello World!";
    }
   }
   Local还用Home就不写了,这不是重要的。。
关键:客户端代码:
/*
 * HelloClient.java
 *
 * Created on 2006年10月9日, 下午10:15
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */package com.wiley.compBooks.chapter3.sessionBean;import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;/**
 *
 * @author chen
 */
public class HelloClient {
    
    /** Creates a new instance of HelloClient */
    public HelloClient() {
    }
    public static void main(String[] args) {
        try {
            Properties props = System.getProperties();
            Context ctx = new InitialContext(props);
            HelloLocalHome Home = (HelloLocalHome) ctx.lookup("HelloHome");
            HelloLocal hello = Home.create();
            System.out.println(hello.hello());
            hello.remove();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}这里有ctx:lookup()函数,运行说是javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file
的错误。。这到底如何在netbeans中进行部署啊???就是jndi问题,我一直弄不明白各位大侠一定要帮帮我啊都困扰几天了