File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Run JNDI example problem 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 "Run JNDI example problem" Watch "Run JNDI example problem" New topic

Run JNDI example problem

nan sh
Ranch Hand

Joined: Jan 05, 2001
Posts: 167
I download this tutorial;
try to run example as following;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Hashtable;
class Lookup {
public static void main(String[] args) {
// Check that user has supplied name of file to lookup
if (args.length != 1) {
System.err.println("usage: java Lookup <filename>");
String name = args[0];
// Identify service provider to use
Hashtable env = new Hashtable(11);
try {
// Create the initial context
Context ctx = new InitialContext(env);
// Look up an object
Object obj = ctx.lookup(name);
// Print it out
System.out.println(name + " is bound to: " + obj);

// Close the context when we're done
} catch (NamingException e) {
System.err.println("Problem looking up " + name + ": " + e);

I put fscontext.jar , providerutil.jar and jndi.jar under JAVA_HOME\jer\lib\ext
I get the following exception;
Problem looking up c:\Java: javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.jndi.fscontext.RefFSContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.jndi.fscontext.RefFSContextFactory]
why can not instantiate class:
com.sun.jndi.fscontext.RefFSContextFactory, fscontext.jar is there.

Have you tried this Mock Exam Testing Engine yet?<br /><a href="" target="_blank" rel="nofollow"></a>
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
set your CLASSPATH to point to the file fscontext.jar, I think this should solve this problem, if you still have the same message check the jar file to see if the class can be found inside it.
nan sh
Ranch Hand

Joined: Jan 05, 2001
Posts: 167
Thanks Marcos.
It realy solves the problem. But I am wondering why JVM cannot see all those *.jar in JAVA_HOME\jer\lib\ext?
I agree. Here's the link:
subject: Run JNDI example problem
It's not a secret anymore!