dcsimg
JNDI on Windows 2000
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   alpesh_patel
Posted On:   Monday, December 2, 2002 03:57 AM

Hi When ever i am running the code attached below i am getting an error javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.jndi.f scontext.RefFSContextFactory. Root exception is java.lang.ClassNotFoundExceptio n: com.sun.jndi.fscontext.RefFSContextFactory import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.Binding; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import java.util.Hashtable; public class Main { public static void main(String [] rgstring) { try { // Create the initial contex   More>>

Hi When ever i am running the code attached below i am getting an error
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.jndi.f
scontext.RefFSContextFactory. Root exception is java.lang.ClassNotFoundExceptio
n: com.sun.jndi.fscontext.RefFSContextFactory


import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.Binding;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;

import java.util.Hashtable;

public
class Main {

public
static
void
main(String [] rgstring) {
try {
// Create the initial context. The environment
// information specifies the JNDI provider to use
// and the initial URL to use (in our case, a
// directory in URL form -- file:///...).
Hashtable hashtableEnvironment = new Hashtable();
hashtableEnvironment.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory"
);
hashtableEnvironment.put(Context.PROVIDER_URL,rgstring[0]);
Context context = new InitialContext(hashtableEnvironment);
// If you provide no other command line arguments,
// list all of the names in the specified context and
// the objects they are bound to.
if (rgstring.length == 1) {
NamingEnumeration namingenumeration = context.listBindings("");
while (namingenumeration.hasMore()) {
Binding binding = (Binding)namingenumeration.next();
System.out.println(
binding.getName() + " " +
binding.getObject()
);
}
}
// Otherwise, list the names and bindings for the
// specified arguments.
else {
for (int i = 1; i < rgstring.length; i++) {
Object object = context.lookup(rgstring[i]);
System.out.println(
rgstring[i] + " " +
object
);
}
}
context.close();
}
catch (NamingException namingexception) {
namingexception.printStackTrace();
}
}
}




   <<Less

Re: JNDI on Windows 2000

Posted By:   Stephen_Ponzio  
Posted On:   Tuesday, January 14, 2003 03:09 PM

I get this same error, but only

(1) sporadically,

(2) when I call the code from C++ through JNI, or

(3) when more than one thread is actively calling the code.


In other words, I don't get the error

(1) sometimes (!! yes, sometimes it just all works!),

(2) when I call the code from a Java test class, or

(3) when the C++ has only one thread calling JNI.


This is despite the facts that

(1) calls so new InitialContext() are synchronized, so no two threads call it at the same time,

(2) the two jar files (fscontext.jar and providerutil.jar) are present as extensions, in jre/lib/ext/, and

(3) I can successfully load the class using Class.forName and even instantiate an instance immediately prior to calling new InitialContext().


This last fact is particularly vexing. The only clue I can imagine is that it has something do with class loaders, but if the class has already been loaded, why would the JVM try to load it again? (And anyway, the extension loader should always find it.)


The stack trace looks like


javax.naming.NoInitialContextException:
Cannot instantiate class: com.sun.jndi.fscontext.RefFSContextFactory.
Root exception is
java.lang.ClassNotFoundException: com/sun/jndi/fscontext/RefFSContextFactory at
java.lang.Class.forName0(Native Method) at
java.lang.Class.forName(Class.java:190) at
com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:40) at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:647) at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:241) at
javax.naming.InitialContext.init(InitialContext.java:217) at
javax.naming.InitialContext.(InitialContext.java:173)



Any ideas or clues will be greatly appreciated!

Re: JNDI on Windows 2000

Posted By:   Nicholas_Whitehead  
Posted On:   Tuesday, December 3, 2002 05:39 PM

Alpesh;

It looks like you are missing the jar file containing the File System Context Factory you are attempting to use. The file name is fscontext.jar and it should be in your classpath.

If you do not have the file, it can be downloaded from the Sun Web Site.

//Nicholas

Re: JNDI on Windows 2000

Posted By:   Benoit_Quintin  
Posted On:   Monday, December 2, 2002 05:55 AM

And we are to assume you are using Sun's AppServer, I suppose??

Is your appserver properly configured and working??

About | Sitemap | Contact