Alright my friend, I'm about to make your day.
There's a but with the JNDI classloader in that it doesn't delegate to its parent
classloader the task of loaded the intial context factory. This means that, while the
web-app classloader knows where your class is, the JNDI one DOESN'T and isn't asking
for any help!
Put this in your pipe and smoke it:
Keeps throwing a "ClassNotFoundException" when it tries to load my context factory.
Turns out that the JNDI classloader is broken and you need to install your own
builder. You can read the docs for more info, also check out this code snippet:
NamingManager.setInitialContextFactoryBuilder( new
InitialContextFactoryBuilder()
{
public InitialContextFactory createInitialContextFactory( Hashtable
environment )
throws NamingException
{
try
{
// Since we're the only ones using this, we can really
disregard the Hashtable.
return( (InitialContextFactory)
((Class.forName("com.sun.jndi.nis.NISCtxFactory")).newInstance()) );
}
catch(InstantiationException e)
{
NISUtils.cat.fatal("Unable to instantiate the JNDI NIS
factory, message ["+e.getMessage()+"]");
throw new NamingException(e.getMessage());
}
catch(IllegalAccessException e)
{
NISUtils.cat.fatal("Unable to access the JNDI NIS factory,
message ["+e.getMessage()+"]");
throw new NamingException(e.getMessage());
}
catch(ClassNotFoundException e)
{
NISUtils.cat.fatal("Unable to find the JNDI NIS factory,
message ["+e.getMessage()+"]");
throw new NamingException(e.getMessage());
}
}
});
Enjoy!
- r
On Fri, 17 Aug 2001 19:48:55 +0530 [EMAIL PROTECTED] wrote:
> hey rob,
> my servlet calls a class which tries to instantiate JNDI's InitialContext
> by passing env Hashtable...
> ....
> env.put(Context.INITIAL_CONTEXT_FACTORY,
> "com.sun.jndi.fscontext.RefFSContextFactory");
> ....
> initialContext = new InitialContext(env);
>
> the class com.sun.jndi.fscontext.RefFSContextFactory is available in the
> jar file in my
> WEB-INF\lib folder. And the error that I get while loading the servlet is
> ....
>
> getInitialContext:exception: javax.naming.NoInitialContextException: Cannot
> instantiate class: com.sun.jndi.fscontext.RefFSContextFactory [Root
> exception is java.lang.ClassNotFoundException:
> com.sun.jndi.fscontext.RefFSContextFactory]
> getInitialContext:More Details: Cannot instantiate class:
> com.sun.jndi.fscontext.RefFSContextFactory
>
> You really are onto helping me, aren't you? if you could solve this one, I
> owe you a mug of
> beer, when you come donw to Bangalore...
> paresh
>
> -----Original Message-----
> From: Rob S. [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 17, 2001 7:34 PM
> To: [EMAIL PROTECTED]
> Subject: Re: problem in loading jar files in WEB-INF\lib directory
>
>
> > Then, the only question remaining is classes in my jar file are not being
> > loaded for
> > some reason. While loading the servlet, somewhere midway, the classes in
> > WEB-INF\lib
> > directory are not being loaded. strange isn't it?
>
> How do you know the classes are not being loaded? What kind of error
> message are you getting?
>
> "Help me help you" =)
>
> - r