• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12561
  • Last Modified:

JNDI Problem (ClassNotFoundException: com.sun.jndi.fscontext.RefFSContextFactory)

i am currently doing some self-study in JNDI by using http://java.sun.com/products/jndi/tutorial/trailmap.html as my tutorial source.

i am using winxp and Java(TM) 2 SDK, Standard Edition Version 1.4.2.

i am able to complie the following example code successfully.
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);
however, when come to execution, i am stucked with the following exception.

C:\DOCUME~1\YANCHE~1\Desktop>dir c:\autoexec.bat
 Volume in drive C has no label.
 Volume Serial Number is 600C-73BF

 Directory of c:\

03/16/2004  04:40 AM                 0 AUTOEXEC.BAT
               1 File(s)              0 bytes
               0 Dir(s)  12,305,121,280 bytes free

C:\DOCUME~1\YANCHE~1\Desktop>java Lookup \
Problem looking up \: javax.naming.NoInitialContextException: Cannot instantiate
 class: com.sun.jndi.fscontext.RefFSContextFactory [Root exception is java.lang.
ClassNotFoundException: com.sun.jndi.fscontext.RefFSContextFactory]

i was wondering whether can i get the class file "com.sun.jndi.fscontext.RefFSContextFactory". i had gone trough the "Common Problems (and Their Solutions)" section under the tutorial. however, i didnt find a clear path on how can i solve this problem :(

any suggestion and solving this problem?

thank you.

yan cheng
  • 2
  • 2
2 Solutions
add jndi.jar to your classpath
Tommy BraasCommented:
You have to look for something at a known path and you have to have a JNDI server running. If you download either J2EE SDK 1.3 or 1.4 you will get a JNDI server.
yccheokAuthor Commented:
i am using J2SE 1.4 SDK standard addition and olso the J2EE 1.4 SDK. i oledi include jndi.jar in my classpath which come with J2EE 1.4 SDK, still didnt work.

from other forum, i realize that i need the following files in my classpath

how can i get the above files?

thank you.

yan cheng
go to http://java.sun.com/products/jndi/downloads/index.html
click on download JNDI 1.2.1
download the File System Service Provider, that should have those files
Tommy BraasCommented:
Do you have the Sun Java System Application Server Platform Edition 8 running? Do you have JNDI names defined in the server? Are you trying to get the context for any of the defined names in the JNDI directory? When getting the initial context from JNDI when you're running your application and server on the same machine can be done with the default constructor for InitialContext, i.e. new InitialContext();
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now