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();
}
}
}