i have tried creating my first ejb. i created all the classes, downloaded the j2ee reference implementation from sun. i used the deploy tool to create the application with the bean and deployed it. i then created the client application to try using it. but.... its giving me this error.
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 users.derekv.CabinClient.main(CabinClient.java:19)
here is my client code.
public class CabinClient {
public static void main(String[] args) {
try {
Context jndiContext = getInitialContext();
Object ref = jndiContext.lookup("java:comp/env/ejb/Cabin");
CabinHome home = (CabinHome)PortableRemoteObject.narrow(ref, CabinHome.class);
Cabin cabin = home.create(1);
cabin.setName("Master Suite");
cabin.setDeckLevel(1);
cabin.setShip(1);
cabin.setBedCount(3);
CabinPK pk = new CabinPK();
pk.id = 1;
cabin = home.findByPrimaryKey(pk);
System.out.println(cabin.getName());
System.out.println(cabin.getDeckLevel());
System.out.println(cabin.getShip());
System.out.println(cabin.getBedCount());
}
catch (Exception e) {
e.printStackTrace();
}
}
public static Context getInitialContext() throws NamingException {
return new javax.naming.InitialContext();
}
}
i have read through all (i think) docs that came with j2ee, and it says something about setting environment variables so that the initial context will be able to connect to the naming service and find the ejb object. but, either i dont understand it, or i'm just plain missing something. i've cruised around sun's site and some other sites as well with no luck... ANY help at this point would be greatly appreciated. thanks.
-
NoIntialContextException (7 messages)
- Posted by: derek van kooten
- Posted on: October 02 2000 13:41 EDT
Threaded Messages (7)
- NoIntialContextException by Ed Roman on October 02 2000 14:24 EDT
- NoIntialContextException by derek van kooten on October 02 2000 15:09 EDT
-
NoIntialContextException by Ed Roman on October 03 2000 12:10 EDT
-
NoIntialContextException by derek van kooten on October 03 2000 08:13 EDT
- NoIntialContextException by lkbm lkbm on October 04 2000 04:07 EDT
-
NoIntialContextException by derek van kooten on October 03 2000 08:13 EDT
-
NoIntialContextException by Ed Roman on October 03 2000 12:10 EDT
- NoIntialContextException by derek van kooten on October 02 2000 15:09 EDT
- NoIntialContextException by derek van kooten on October 06 2000 15:37 EDT
- NoIntialContextException by Atit Kumar on November 21 2000 18:24 EST
-
NoIntialContextException[ Go to top ]
- Posted by: Ed Roman
- Posted on: October 02 2000 14:24 EDT
- in response to derek van kooten
just enter import <classname(cabin,intrfaces)> at the begining -
NoIntialContextException[ Go to top ]
- Posted by: derek van kooten
- Posted on: October 02 2000 15:09 EDT
- in response to Ed Roman
i do have the import statments, i didnt include them in my question. the program compiles fine. i get the error when i run the program. -
NoIntialContextException[ Go to top ]
- Posted by: Ed Roman
- Posted on: October 03 2000 00:10 EDT
- in response to derek van kooten
have u given any jndi name to cabin.if yes in the lookup method give that name. -
NoIntialContextException[ Go to top ]
- Posted by: derek van kooten
- Posted on: October 03 2000 08:13 EDT
- in response to Ed Roman
yes i have given cabin a name, as you can see from the code that i included in my question..... read the code where it calls the method "lookup". -
NoIntialContextException[ Go to top ]
- Posted by: lkbm lkbm
- Posted on: October 04 2000 16:07 EDT
- in response to derek van kooten
Hey Manish
If u dont know things..its not necessary to give bullshit.its better to keep ur trap shut :-)
lkbm -
NoIntialContextException[ Go to top ]
- Posted by: derek van kooten
- Posted on: October 06 2000 15:37 EDT
- in response to derek van kooten
well i think i figured out what i needed to do, i needed to add more classes to my CLASSPATH. i added every jar and its brother to my classpath and it worked. oh well.... -
NoIntialContextException[ Go to top ]
- Posted by: Atit Kumar
- Posted on: November 21 2000 18:24 EST
- in response to derek van kooten
Hi,
I jsut started using J2EE Server which I downloaded from Javasoft.com. I was trying to run the same example and getting this error. I added all the .jar files in classpath but still getting this error.
javax.naming.NoInitialContextException: Need to specify class name in environmen
t or system property, or as an applet parameter, or in an application resource f
ile: java.naming.factory.initial
at java.lang.Throwable.<init>(Compiled Code)
at java.lang.Exception.<init>(Compiled Code)
at javax.naming.NamingException.<init>(Compiled Code)
at javax.naming.NoInitialContextException.<init>(Compiled Code)
at javax.naming.spi.NamingManager.getInitialContext(Compiled Code)
at javax.naming.InitialContext.getDefaultInitCtx(Compiled Code)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Compiled Code)
at javax.naming.InitialContext.lookup(Compiled Code)
at ConverterClient.main(Compiled Code)
Could you please anyone tell me what exactly is the problem. I have checked the lookup method and also deployed correctly as per documentation.
Here is the client code.....
***************************
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import Converter;
import ConverterHome;
public class ConverterClient {
public static void main(String[] args) {
try {
Context initial = new javax.naming.InitialContext();
Object objref = initial.lookup("java:MyConverter");
ConverterHome home =
(ConverterHome)PortableRemoteObject.narrow(objref,
ConverterHome.class);
Converter currencyConverter = home.create();
double amount = currencyConverter.dollarToYen(100.00);
System.out.println(String.valueOf(amount));
amount = currencyConverter.yenToEuro(100.00);
System.out.println(String.valueOf(amount));
} catch (Exception ex) {
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}
}
*******************************************
Please reply as soon as you can.
Thanks in advance.