NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

javax.naming.NoInitialContextException while Running the EJB client

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
mukesh.sheoran



Joined: 19 Oct 2009
Posts: 2

PostPosted: Mon Oct 19, 2009 3:41 pm    Post subject: javax.naming.NoInitialContextException while Running the EJB client Reply with quote

I am running a simples EJB program using NetBeans.. server GlassFish. I created the session bean, home and remote interface and then deployed it I deployed successfully. then I wrote this client class and tried to invoked the Bean method. while running the class the I am getting this exception

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(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at Examples.HelloClient.invoke(HelloClient.java:2Cool
at Examples.HelloClient.main(HelloClient.java:19)

Client Class code is :

package Examples;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

/**
*
* @author mukesh
*/
public class HelloClient {

public static void main(String [] args){
new HelloClient().invoke();

}

public void invoke(){

try{
Context ic = new InitialContext();
Object o = ic.lookup("HelloWorldBean");
HelloWorldRemoteHome home = (HelloWorldRemoteHome) PortableRemoteObject.narrow(o, HelloWorldRemoteHome.class);

HelloWorldRemote remote = home.create();
System.out.println("We run our first EJB>>>"+remote.invokeHello());
}catch(Exception e){
e.printStackTrace();
}
}
}


Please help me out.. Thanks in advance
Back to top
bftanase



Joined: 12 Oct 2009
Posts: 9

PostPosted: Mon Oct 19, 2009 6:21 pm    Post subject: Reply with quote

With EJB 3.0 you can use annotations. Have you tried it?

The code should look smth like this...

Code:

[...]
import HelloWorldRemoteHome;

[...]

@EJB
private static HelloWorldRemoteHome  home;

public static void main(String [] args){
     home.invokeHello();
}



This should inject the whole required initial context stuff...
Back to top
mukesh.sheoran



Joined: 19 Oct 2009
Posts: 2

PostPosted: Tue Oct 20, 2009 2:44 am    Post subject: Reply with quote

No, I have not tried this as I am working on a EJB 2.0 project... Can Any body please suggest me smthng with EJB 2.0
Back to top
smoczyna



Joined: 08 Jan 2009
Posts: 34

PostPosted: Tue Nov 10, 2009 2:14 pm    Post subject: Reply with quote

For EJB2 you need to build deployment descriptor
try this http://www.vipan.com/htdocs/ejb-jar.xml.html
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo