Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes javax.naming.NoInitialContextException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "javax.naming.NoInitialContextException" Watch "javax.naming.NoInitialContextException" New topic
Author

javax.naming.NoInitialContextException

monica deighan
Greenhorn

Joined: Nov 13, 2001
Posts: 1
I have coded and compiled a test client to use a simple EJB.
package helloworld;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

//Client code that invokes methods on simple stateless session bean.
public class HelloClient {

public static void main (String [] args) {
try {
System.out.println("Client Running");
//Get a naming context
InitialContext jndiContext = new InitialContext();
System.out.println("Got Context");

//Get a reference to the HelloBean
Object ref = jndiContext.lookup("hello\Hello");
System.out.println("Got Reference");

//Get a reference from this to the bean's Home interface
HelloHome home = (HelloHome)PortableRemoteObject.narrow(ref, HelloHome.class);

//Create a Hello object from the Home interface
Hello hello = home.create();

//Call the hello() method, and print it
System.out.println(hello.hello());

//Done with EJB object, so remove it
hello.remove();

} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
When I run the client I am getting the following error message
Client Running Got Context 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 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:643) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246) at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:283) at javax.naming.InitialContext.lookup(InitialContext.java:350) at helloworld.HelloClient.main(HelloClient.java:27) Process Exit...
I have a jndi.properties file as follows and I have added this file to my classpath.
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming rg.jnp.interfaces
In addition, I have the jboss-j2ee.jar file in my classpath.
Would greatly appreciate any assistance on the above.
Regards
Monica
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 565
when you create the InitialContext, don't you have to tell it which class to use like so:


not that i'm an expert with this, in fact i never got it to work


I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.naming.NoInitialContextException
 
Similar Threads
Naming Exception at runtime when running client.
JNDI error while executing client
EJB compiled but not executing....help?
NoInitialContextException
EJB-Client Error.