Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

javax.naming exceptions  RSS feed

 
ved gunjan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!All
I'm trying to bind and then lookup valid file object in JNDI using the following method and code.Im using j2sdk1.4.Im running my JNDI client as a standlone java class and not using ant App server. I have placed jndi.jar,fscontext.jar,providerutil.jar in <J2SDK_HOME>\jre\lib\ext folder

Here's the code
public static void main(String[] args)//throws FileNotFoundException
{
File BP_xml_file;
file=new File("C:\\work_dir\\helloworld.txt");
System.out .println("filename" +""+ file.getName());
System.out.println(file);
try
{
if(file.exists())//throw new FileNotFoundException();
System.out.println("file found");
else
System.out.println("file not present");
}
catch(Exception fe)
{
System.out.println(fe);
}
// Set up environment for creating the initial context
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL,"file:c:\\work_dir\\");

try {
// Create the initial context
Context ctx = new InitialContext(env);

//bind the object
ctx.bind("myfile",file);
// Look up an object
File fileobj = (File)ctx.lookup("myfile");
System.out.println(fileobj);
//close the context
ctx.close();
}
catch (NamingException e)
{
System.err.println("Problem looking up " + ": " + e);
}
}

}

Its giving me the following error
javax.naming.OperationNotSupportedException: Can only bind References or Referenceable objects

Any idea whats going on and whats going wrong
Regards
Ved
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ved,

In your line,
file:c:\\work_dir\\

It should be,
file://c:\\work_dir\\

Try it and see if it works.

Regards
Maulin
 
ved gunjan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maulin Vasavada:
Hi ved,

In your line,
file:c:\\work_dir\\

It should be,
file://c:\\work_dir\\

Try it and see if it works.

Regards

Thnx Maulin for your help.I tried the solution that u mentioned but still is giving me the same error.
javax.naming.OperationNotSupportedException: Can only bind References or Referenceable objects
Got no clue what to do.Can u help me??
Regards
ved

Maulin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!