• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NoInitialContextException error

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
}
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic