Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » eclipse 3.4 - ejb - jboss - jndi-name
eclipse 3.4 - ejb - jboss - jndi-name [message #221771] Wed, 24 September 2008 10:14 Go to next message
Silvan Spross is currently offline Silvan Spross
Messages: 2
Registered: July 2009
Junior Member
hi all

i have problems to get an ejb working in my client.

first a short overview, i have:

an ejb remote:

--
import javax.ejb.Remote;

@Remote
public interface Computer {
public double compute(double a, double b);
}
--

an ejb:

--
import javax.ejb.Stateless;

@Stateless(mappedName = "Computer")
public class ComputerBean implements Computer {

public ComputerBean() {
// TODO Auto-generated constructor stub
}

public double compute(double a, double b) {
return a + b;
}
}
--

and a 'client':

--
import java.util.Hashtable;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;

public class ComputerUser {

@EJB
private static Computer computer;

public ComputerUser(){
}

public static void main(String[] args) {
ComputerUser client = new ComputerUser();
client.doTest();
}

public void doTest()
{
try {
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
env.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
env.put(Context.PROVIDER_URL, "127.0.0.1:1099");

InitialContext ic = new InitialContext(env);
computer = (Computer)ic.lookup("java:comp/env/ejb/Computer");

} catch (Exception e){
System.out.println(e);
}

System.out.println(computer);
System.out.println(computer.compute(1,2));
}
}
--

i have an 'EAR', a 'bean' and a 'client' project. both are added to the
EAR project and the deployment to the installed jboss 4.2 server works
without errors.

now if i try to debug the 'client' (ComputerUser) he can't find the
Computer Bean:

javax.naming.NameNotFoundException: comp not bound

someone any idea what i'm doing wrong?
Re: eclipse 3.4 - ejb - jboss - jndi-name [message #221784 is a reply to message #221771] Wed, 24 September 2008 11:12 Go to previous message
Silvan Spross is currently offline Silvan Spross
Messages: 2
Registered: July 2009
Junior Member
i got it! it works with:

--
public void doTest() {
try {
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "127.0.0.1:1099");

InitialContext ic = new InitialContext(env);
Object ref = ic.lookup("BernhardEAProject/ComputerBean/remote");
computer = (Computer)PortableRemoteObject.narrow(ref,
Computer.class);

} catch (Exception e){
System.out.println(e);
}

System.out.println(computer);
System.out.println(computer.compute(1,2));
}
--
Previous Topic:Deploy Servlet Web App to JBoss
Next Topic:JSF taglib directive mistakenly inserted
Goto Forum:
  


Current Time: Thu Aug 21 06:12:02 EDT 2014

Powered by FUDForum. Page generated in 0.01492 seconds