| Author |
NoInitialContextException: Prob
|
charmy jain
Greenhorn
Joined: Dec 17, 2005
Posts: 19
|
|
hi, Bean Code : i create a stateless session bean and in that include 2 method of String getInfo() and setInfo(String info) and process is same like create a bean int netbeans5.0 beta version. and we user netbean 5.0 beta and jboss server and my client code is package cartclient; import cart.CartRemote; import cart.CartRemoteHome; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; public class Main { public static void main(String[] args) { try{ Context con = new InitialContext(); Object objRef = con.lookup("ejb/CartBean"); CartRemoteHome home = (CartRemoteHome)PortableRemoteObject.narrow(objRef,CartRemoteHome.class); CartRemote cartremote = home.create(); cartremote.setInfo("Hello call a ejb method ") ; System.out.println("The Message From Bean " + cartremote.getInfo()); }catch(Exception ex){ System.out.println("The Error : " + ex); } } } but i have error is The 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 plz, help me to find a error and solve that propb. thanks
|
 |
Mukesh Sehgal
Greenhorn
Joined: Oct 10, 2003
Posts: 11
|
|
instead of Object objRef = con.lookup("ejb/CartBean"); try: Object objRef = con.lookup("env/comp/ejb/CartBean"); not sure but worth trying....
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
You might have to set some properties in jndi.properites Like: java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.provider.url=localhost:1099 And please change your name according to the policy : http://www.javaranch.com/name.jsp Thanks. [ April 03, 2006: Message edited by: Satou kurinosuke ]
|
[My Blog]
All roads lead to JavaRanch
|
 |
charmy jain
Greenhorn
Joined: Dec 17, 2005
Posts: 19
|
|
hi, i try it and it is not work.
|
 |
charmy jain
Greenhorn
Joined: Dec 17, 2005
Posts: 19
|
|
try to change a name but it is not work and again i will try then it is work now... ok thnaks for inform me... and plz, help for solved a prob because it is also not wark i prepare stateless session bean into netbeans id and compile it and i used a jboss server and now i want to call that it's ejb methods from simple java class meanse void main method so what i do?? plz, reply me thnaks
|
 |
charmy jain
Greenhorn
Joined: Dec 17, 2005
Posts: 19
|
|
hi, i got a soluction of my problem , so soluction is : package com; import com.sun.rsasign.c; import javax.naming.InitialContext; /** * * @author Shivam1 */ public class testbean { /** Creates a new instance of testbean */ public testbean() { try{ com.exampleRemote updateAvailableBudgetRemote = lookupexampleBean() ; System.out.println(updateAvailableBudgetRemote.getInfo()); }catch(Exception ex){ System.out.println(ex); } } /** * @param args the command line arguments */ public static void main(String[] args) { testbean t1 = new testbean(); } private com.exampleRemote lookupexampleBean() { try { InitialContext ctx = new InitialContext(); ctx.addToEnvironment("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); ctx.addToEnvironment("java.naming.factory.url.pkgs", "org.jboss.naming rg.jnp.interfaces"); ctx.addToEnvironment("java.naming.provider.url","localhost"); Object remote = ctx.lookup("test/Tester"); com.exampleRemoteHome rv = (com.exampleRemoteHome) javax.rmi.PortableRemoteObject.narrow(remote, com.exampleRemoteHome.class); return rv.create(); } catch(javax.naming.NamingException ne) { java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne); throw new RuntimeException(ne); } catch(javax.ejb.CreateException ce) { java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce); throw new RuntimeException(ce); } catch(java.rmi.RemoteException re) { java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,re); throw new RuntimeException(re); } } } and plz define , "test/Tester" is jndi name into jboss.xml file at ejb module.. hahaha u got a result
|
 |
 |
|
|
subject: NoInitialContextException: Prob
|
|
|