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

[1781 byte] By [safinahmeda] at [2007-10-2 10:27:50]
# 1
if you use Sun Application Server try to change the port to 4700
santiago747a at 2007-7-13 2:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

We recommend using the no-arg InitialContext constructor when writing a stand-alone client that accesses EJBs within SUN AS 8.x. As long as appserv-rt.jar is in your client's classpath, the correct naming provider will be bootstrapped. You can set

-Dorg.omg.CORBA.ORBInitialHost=<host> and

-Dorg.omg.CORBA.ORBInitialPort=<port>

when starting the client JVM. These default to localhost and 3700.

ksaksa at 2007-7-13 2:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

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?

nawad980a at 2007-7-13 2:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

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

ksaksa at 2007-7-13 2:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
set Enviorment variable j2ee_home =sun/appserver/lib/j2ee.jar
rupabhatta at 2007-7-13 2:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

> set Enviorment variable j2ee_home =sun/appserver/lib/j2ee.jar

Dear rupabhatt,

Can you explain why should we do that? As per my knowledge, this environment variable is used by the batch files to start and stop the j2ee server instance. the j2ee.jar should be in the application's classpath, either through the -cp option of the java command, or using the CLASSPATH environment variable.

Best regards,

nawad980a at 2007-7-13 2:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7

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

ishkmia at 2007-7-13 2:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8
You can find more information on accessing remote EJBs in the Java EE SDK / Glassfish EJB FAQ :https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html --ken
ksaksa at 2007-7-13 2:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...