Hi all,
I'm new to EJB. I'm writing a toy EJB, and having problem running the client
(bean can be deployed successfully in Eclipse) When running the client, it generates
javax.naming.NameNotFoundException: HelloBean not bound.
Please help. THANKS A LOT!!!
my config:
IDE: Eclipse
JBOSS: 4.0.5
//INTERFACE:
package examples.session.stateless;
import javax.ejb.*;
public interface Hello {
public String hello() ; //throws java.rmi.RemoteException;
}
//BEAN CLASS
package examples.session.stateless;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.ejb.*;
@Stateless
@Remote(Hello.class)
public class HelloBean implements Hello {
public String hello () {
System.out.println("in hello()...");
return "Hello, World!";
}
}
EJB-JAR.XML
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_ID" version="2.1"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
JBoss Hello World Application
<display-name>HelloBean</display-name>
<enterprise-beans>
<ejb-name>HelloBean</ejb-name>
</enterprise-beans>
</ejb-jar>
CLIENT
package examples.session.stateless;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
public class HelloEJBClient {
public static void main( String [] args )
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost:1099");
env.put("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
try
{
InitialContext ctx = new InitialContext(env);
Hello hello = (Hello) ctx.lookup( "HelloBean" );
System.out.println(hello.hello());
}
catch ( Exception e )
{
e.printStackTrace();
System.out.println( "Chen - Exception: " + e.getMessage() );
}
}
}
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4041983#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...