Forums Register Login

javax.naming.NoInitialContextException while Running the client

+Pie Number of slices to send: Send
I am running a simples EJB program using NetBeans.. server GlassFish. I created the session bean, home and remote interface and then deployed it I deployed successfully. then I wrote this client class and tried to invoked the Bean method. while running the class the I am getting this exception

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at Examples.HelloClient.invoke(HelloClient.java:28)
at Examples.HelloClient.main(HelloClient.java:19)

Client Class code is :

package Examples;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

/**
*
* @author mukesh
*/
public class HelloClient {

public static void main(String [] args){
new HelloClient().invoke();

}

public void invoke(){

try{
Context ic = new InitialContext();
Object o = ic.lookup("HelloWorldBean");
HelloWorldRemoteHome home = (HelloWorldRemoteHome) PortableRemoteObject.narrow(o, HelloWorldRemoteHome.class);

HelloWorldRemote remote = home.create();
System.out.println("We run our first EJB>>>"+remote.invokeHello());
}catch(Exception e){
e.printStackTrace();
}
}
}


Please help me out.. Thanks in advance
+Pie Number of slices to send: Send
try this :
Object o = ic.lookup("ejb/HelloWorldBean");
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1280 times.
Similar Threads
Jndi Error In Client Application
Running EJB Client
Simple Hello example for JBOSS
How can we use JNDI?
javax.naming.NoInitialContextException
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:29:17.