This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NamingException was thrown

 
suresh sai
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
....?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic