This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Client does not run - NoInitialContextException ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Client does not run - NoInitialContextException !" Watch "Client does not run - NoInitialContextException !" New topic
Author

Client does not run - NoInitialContextException !

Loukas G
Greenhorn

Joined: Mar 04, 2004
Posts: 7
Hi, I am new at EJB and i read Head First EJB.I use Windows XP,J2EE Reference Implementation and J2SDK 1.4.2.When i tried to run the first example and specifically the client (AdviceClient) the following message was displayed:
E:\source\projects\advice>java AdviceClient
Context Created!!!
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 javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
40)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
a:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at AdviceClient.go(AdviceClient.java:21)
at AdviceClient.main(AdviceClient.java:12)

---------------------------CODE---------------------------------------------
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;

public class AdviceClient
{
public static void main(String[] args)
{
new AdviceClient().go();
}
public void go() {
try
{
Context ic = new InitialContext();
System.out.println("Context Created!!!");
Object o = ic.lookup("Advisor");
System.out.println("Lookup DONE!!!");
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
System.out.println("Narrowing DONE!!!");
Advice advisor = home.create();
System.out.println("Remote Object Created!!!");
System.out.println(advisor.getAdvice());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}

----------------------------------------------------------------------------
Now from the message i think that somewhere i must specify the properties of InitialContext.Am i right and if i am where and how can i do this? Kathy,Bert HELP please!
Lahiru Abeydeera
Ranch Hand

Joined: Nov 05, 2004
Posts: 44
I'm also having the same problem. Do we have to give any JNDI parameters? . Anyway I know it's something wrong with the client not EJB. Because it worked when i used a servlet
Can anyone help me?

Thanx in advance!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Client does not run - NoInitialContextException !
 
Similar Threads
Need Help with AdviceClient Error
Problem while Running First Example Of HFEJB.
problem with creating client in J2ee
Client does not run
how to run the AdviceClient