File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.naming.NoInitialContextException

 
monica deighan
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 567
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic