aspose file tools*
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 JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "NoInitialContextException error" Watch "NoInitialContextException error" New topic
Author

NoInitialContextException error

brian buckholz
Greenhorn

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(SimpleSessionClient.java:22)
C:\brian\j2ee-wrox\chap8\SimpleSessionApp>

-----------------------------------------------------------
echo %CLASSPATH%
.;c:\.;c:\j2sdk1.4.2\bin;c:\j2sdkee1.4\lib\j2ee.jar;c:\brian\j2ee-wrox\chap8\SimpleSessionApp\SimpleSessionAppClient.jar
-----------------------------------------------------------
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 =
simpleSession.getEchoString(args[i]);
System.out.println("sent string: " + args[i]
+ ", received string: " + returnedString);
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NoInitialContextException error