javax.naming.NameNotFoundException
Hi,
i have a group of entity beans, and a session bean (called sessionFacadeBean)
I'm trying to create a simple Console Application to call the Session Bean
My code isHashtable hash =new Hashtable();
hash.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.cosnaming.CNCtxFactory");
hash.put(Context.PROVIDER_URL,"corbaname:iiop:localhost:3700");
Context ctx =new InitialContext(hash);
home = (sessionFacadeRemoteHome) PortableRemoteObject.narrow(ctx.lookup("sessionFacadeBean"), sessionFacadeRemoteHome.class);
As simple as this, but i get this exceptionjavax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
at com.sun.jndi.cosnaming.ExceptionMapper.mapException(ExceptionMapper.java:44)
at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:453)
at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:492)
at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:470)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at testingejb.Main.main(Main.java:41)
Caused by: org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHelper.java:72)
at org.omg.CosNaming._NamingContextStub.resolve(_NamingContextStub.java:251)
at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:440)
... 4 more
Any ideas? I'm using Sun Studio Enterprise 8 to develop, with the Sun Application Server 8.1
Thank you
I don't get it!! I really don't!!!
The code in the last post worked fine for me. Here's what I did:
String host = "192.168.0.143"; //server machine IP
String port = "3700"; //port
System.setProperty("org.omg.CORBA.ORBInitialHost", host);
System.setProperty("org.omg.CORBA.ORBInitialPort", port);
InitialContext context = new InitialContext();
Object obj = context.lookup("ejb/HelloBean");
HelloHome home
= (HelloHome) PortableRemoteObject.narrow(obj, HelloHome.class);
I put the j2ee.jar,appserv-rt.jar - and the returned EJB Client Jar of course - to my classpath, and it works fine.
The problems is I've been searching the whole day for a good calrification of what really is going on, but I wasn't able to find any.
I found many posts that suggests what the first post did:
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
props.put(Context.PROVIDER_URL, "iiop://localhost:3700");
//OR
props.put(Context.PROVIDER_URL, "corbaname:iiop:localhost:3700");
But whenever I do any of that, it gives me the same exception.
Even when I perform the lookup using "java:comp/env/ejb/HelloBean"
, it gives me a nasty javax.naming.NameNotFoundException
So does anyone have, or knows any place that has, a good explanation for this?
Even better would be to set the org.omg.CORBA.. properties as -D properties when starting the client JVM to avoid hardcoding them.The reason the java:comp/env lookup doesn't work is that this kind of stand-alone java client is NOT a J2EE component, therefore it does not have a J2EE component environment (java:comp/env), nor is it portable.Only J2EE components ( Application Clients, web components, ejbs) can define environment dependencies and access java:comp/env.
See the Clients chapter of the SUN AppServer developer's guide for more info :
http://docs.sun.com/source/819-0079/dgacc.html
also u can use
System.setProperty("org.omg.CORBA.ORBInitialHost","127.0.0.1");
System.setProperty("org.omg.CORBA.ORBInitialPort","3700"); // default is 3700
and makesure that The Following Jar files are in the class path
appserv-rt.jar - available at install_dir/lib
j2ee.jar - available at install_dir/lib
imqjmsra.jar - available at install_dir/lib/install/aplications/jmsra