aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes NamingException was thrown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "NamingException was thrown" Watch "NamingException was thrown" New topic
Author

NamingException was thrown

suresh sai
Ranch Hand

Joined: Jul 16, 2007
Posts: 62
Hi all .,

I am trying to execute a simple JNDI example. The code is as shown below.

try{
Context initialContext=new InitialContext();
initialContext.bind("name", "Suresh Sai");
Object stringObject= initialContext.lookup("name");
System.err.println("the string object..... "+stringObject.toString());
}
catch (NamingException ne)
{
System.err.println("naming exception was thrown... "+ne.getMessage());
}


Its compiling,But while running its throwing NamingException ..,

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

Is there any wrong with the code? My main aim is , to creat a name for an object and to access that object through that name.

Please halp me.And also suggest me some good books and resources for JNDI.

Thanks in Advance
Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
Hi. Your code uses the API, but looks like you either completely lack a provider, or you have a provider in your classpath, but you didn't configure it. Please take a look at this:
http://java.sun.com/products/jndi/tutorial/basics/prepare/initial.html
which tells you how to basically configure one. You can do it with a Hashtable, or using properties files in different locations. Follow this:
http://java.sun.com/products/jndi/tutorial/beyond/env/index.html (go to the next 2 pages to learn more).
If you don't have a provider, go here:
http://java.sun.com/products/jndi/serviceproviders.html
and choose one. When I was learning about JNDI, I used File System provider and LDAP (but you need a LDAP server to use it, I used OpenLDAP).
Hope this helps.
[ December 30, 2008: Message edited by: Raf Szczypiorski ]
suresh sai
Ranch Hand

Joined: Jul 16, 2007
Posts: 62
Hi Raf.,

Thanks for the reply.Could you please tell me which service provider Do I need to use? There are lot of service providers ..RMI,CORBA,LDAP etc.Which one is suitable to the above code .I have already configured RMIRegistry.jar. Is this not enough?
suresh sai
Ranch Hand

Joined: Jul 16, 2007
Posts: 62
Hi Raf.,
Thanks for the reply.Could you please tell me what is the suitable service provider for the above code.There are lot of service providers like RMI, LDAP,CORBA etc.I have already configured RMIRegistry.jar.Is this enough?
....?
 
Don't get me started about those stupid light bulbs.
 
subject: NamingException was thrown