On 08/05/2001 21:39:31 Hawkins, Keith (Keith) wrote:
> I have a servlet that uses the Sun's jndi classes to access a LDAP
> database.
>
> I have a test program that can run my servlet's jndi access methods
> without any problem.
>
> When I install and run the servlet under tomcat,  the class loader
> throws a ClassNotFoundException
> for the com.sun.jndi.ldap.LdapCtxFactory class.
> (Stack trace shown below.)
>
> I have the jndi jar files in the WEB-INF/lib directory along with the
> jar file for my servlet code.
>
> Why can't tomcat load the same classes that my test program can if the
> same jar files are used in both cases?
>
> How can I determine the classpath that is in effect when my servlet is
> attempting to load the class?
>
> (I tried using System.getProperty("java.class.path") but the results
> didn't even show the jar file containing
>  my servlet classes, so I know this is not showing me the true
> classpath)
>
-- snip

Keith, I haven't tried this out but I think the following will help ...

Tomcat doesn't use the classpath to load classes in WEB-INF/lib or
WEB-INF/classes, it uses a special classloader that just monitors those
directories.  When JNDI attempts to load the LDAP service provider classes it
uses the current thread's contextClassLoader which, unfortunately, Tomcat
doesn't setup correctly.  There is a class
org.apache.tomcat.request.Jdk12Interceptor which does set the context class
loader correctly for each request so you should add this as a request
interceptor to your server.xml file.

.../Bob


-----------------------------------------------------------------
        Visit our Internet site at http://www.reuters.com

Any views expressed in this message are those of  the  individual
sender,  except  where  the sender specifically states them to be
the views of Reuters Ltd.

Reply via email to