Forums Register Login

regarding simple JNDI program

+Pie Number of slices to send: Send
Hi All.,

I have written a simple JNDI program in IBM RAD.While running its showing
"Cannot instantiate class: com.sun.jndi.fscontext.RefFSContextFactory " Exception. After that I have downloaded and included fscontext.jar in the libraries. But it`s showing another exception...

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jndi/toolkit/chars/CharacterEncoder

Here I am giving complete code.

package mypackage;

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class NamingExample {

public static void main(String []l){
Hashtable environment=new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
try{
Context intialContext=new InitialContext(environment);
String name="D:\\sureshsai";
Object object=intialContext.lookup(name);
System.err.println("the name ... "+name+" is bound to "+object);
}catch (NamingException ne) {
System.err.println("naming exception was thrown... "+ne.getMessage());
}

}
}

Please help me to make the code runnable.
+Pie Number of slices to send: Send
1) Are your jars on your classpath ?
2) then double check (unzip) that class in is the jars (it's meant to be).

Now possibly what is the problem ..

3) Check the class file (java) versions of the related classes eg if old java tries to link to new class files it'll say can't find the file when what it means is can't find a compatiable version so you need to check your Java version and the version of the class files in the two jars all are appropriate to work together ...

easiest way make sure the jars come from the same place and upgrade Java to the latest.

4) Failing that check they haven't done anything 'unique' in the MANIFEST.INF with regards to class paths etc etc
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3761 times.
Similar Threads
NoInitialContextException
Jndi - can't find
JNDI - can't lookup an object
Run JNDI example problem
Naming Problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:03:57.