小弟刚学ejb2.1,在MyEclipse上做了一个最简单的web工程-----HelloWorld, 运行时报如下错误。1.错误
Exception in thread "main" javax.naming.NameNotFoundException: HelloHome not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
在网上找了一下,也有这方面的问题和解决办法,但是试了都不行。2.文件
第一个类
package example;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
public interface Hello extends EJBObject {
public String hello() throws RemoteException;
}第二个类
package example;import java.rmi.RemoteException;import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;public class HelloBean implements SessionBean {

private SessionContext ctx; public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub } public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub } public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub } public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {
// TODO Auto-generated method stub
ctx = arg0; }

public String hello(){
System.out.println("hello");
        return "Hello World!"; 
}}第三个类
package example;import java.rmi.RemoteException;import javax.ejb.EJBHome;public interface HelloHome extends EJBHome {    Hello create() throws RemoteException;

}第四个类,用来测试的package example;import java.util.Hashtable;import javax.naming.Context;
import javax.naming.InitialContext;public class Client { public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
// Properties   props   =   new   Properties(); 

Hashtable props = new Hashtable(); props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
props.put(Context.PROVIDER_URL,"jnp://localhost:1099");

//        props.setProperty( "java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"); 
//        props.setProperty( "java.naming.provider.url","jnp://localhost:1099"); 
//        props.setProperty( "java.naming.factory.url.pkgs","org.jboss.naming");
        Context ctx = new InitialContext(props);
        Object obj = ctx.lookup("HelloHome");
        HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);
    Hello hello = home.create();
    System.out.println(hello.hello());
    hello.remove();
}
}
第一个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>
      <ejb-name>Hello</ejb-name>
      <home>example.HelloHome</home>
      <remote>example.Hello</remote>
      <ejb-class>example.HelloBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>
  </enterprise-beans>
</ejb-jar>第二个XML文件<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd"><jboss>
  <enterprise-beans>
    <session>
      <ejb-name>Hello</ejb-name>
      <jndi-name>HelloHome</jndi-name>
    </session>
  </enterprise-beans>
</jboss>
3.实现步骤
我将三个类文件放在example包中,XML文件放在META-INF文件夹下,然后将整个项目打包成JAR文件,放在D:\Software\jboss4\jboss-4.0.3SP1\server\default\deploy目录下(不包含上面贴的第四个类)。4.尝试了很多方法,均失败,求助大虾帮忙。