tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rob S." <rsli...@sfu.ca>
Subject Re: problem in loading jar files in WEB-INF\lib directory
Date Thu, 01 Jan 1970 00:00:00 GMT
Ugh, mispellings and whatnot aside =) each time I come across a little gotcha like that, I
email it to myself and stick it in my "Wacky Java Experiences" folder.  That code snippet
is the result of searching the mailing list archives and the java.sun.com forums and some
other places I probably can't remember.

Anyway, yeah, it should do the trick for you!

- r

On Fri, 17 Aug 2001 7:23:50 PDT rslifka@popserver.sfu.ca wrote:
> 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 tomcat-user@jakarta.apache.org 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:rslifka@sfu.ca]
> > Sent: Friday, August 17, 2001 7:34 PM
> > To: tomcat-user@jakarta.apache.org
> > 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
> 
> 




Mime
View raw message