File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes NoInitialContextException error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "NoInitialContextException error" Watch "NoInitialContextException error" New topic

NoInitialContextException error

brian buckholz

Joined: Feb 08, 2003
Posts: 5
I am using the Sun Ref Server J2EE 1.4, Beta 2 with JDK 1.4.2 on a Windows XP desktop.
I am using an EJB example and have the following app error when I try to run the client code.
Can anybody help with this? thanks!
the error, classpath settings, and code are below...
C:\brian\j2ee-wrox\chap8\SimpleSessionApp>java client.SimpleSessionClient test argument
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(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at client.SimpleSessionClient.main(

package client;
import java.util.*;
import beans.SimpleSession;
import beans.SimpleSessionHome;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
public class SimpleSessionClient {
public static void main(String[] args) {
try {
// Get a naming context
InitialContext jndiContext = new InitialContext();
// Get a reference to the SimpleSession JNDI entry
Object ref = jndiContext.lookup("ejb/beans.SimpleSession");
// Get a reference from this to the Bean's Home interface
SimpleSessionHome home = (SimpleSessionHome)
PortableRemoteObject.narrow(ref, SimpleSessionHome.class);
// Create a SimpleSession object from the Home interface
SimpleSession simpleSession = home.create();

// loop through the words
for (int i = 0; i < args.length; i++) {
String returnedString =
System.out.println("sent string: " + args[i]
+ ", received string: " + returnedString);
} catch(Exception e) {
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
When you create an InitialContext to a remote JNDI service (such as the J2EE SDK server running as a separate process), you need to specify certain properties that are vendor-specific. Usually they are:
- Factory class name
- Network address of the JNDI server
- Principal
- Credentials
For J2EE SDK, I can't remember the values. Have you tried Googling around? The samples that come along with the SDK could also be helpful...

[ July 11, 2003: Message edited by: Lasse Koskela ]

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: NoInitialContextException error
It's not a secret anymore!