200: javax.naming.NoInitialContextException: Cannot instantiate class:
com.sun.jndi.ldap.LdapCtxFactory. Root exception is
java.lang.ClassNotFoundException: com/sun/jndi/ldap/LdapCtxFactory
200: at java.lang.Class.forName0(Native Method)
200: at java.lang.Class.forName(Class.java:199)
200: at
com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:49)
200: at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:660)
200: at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:250)
200: at javax.naming.InitialContext.init(InitialContext.java:226)
200: at javax.naming.InitialContext.<init>(InitialContext.java:202)
200: at
javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:87)
200: at
MetODSRegistrationServlet.registerUser(MetODSRegistrationServlet.java,
Compiled Code)
200: at
MetODSRegistrationServlet.doPost(MetODSRegistrationServlet.java:203)
200: at javax.servlet.http.HttpServlet.service(HttpServlet.java:747)
200: at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
200: at
newatlanta.servletexec.ServletExec.processServletRequest(ServletExec.java)
200: at
newatlanta.servletexec.ServletExec.ProcessRequest(ServletExec.java, Compiled
Code)
200: at
newatlanta.servletexec.ServletExec.ProcessRequest(ServletExec.java)
The error from the EJB is much the same. The source code is really simple,
and is stock-standard from our research on the net.
Hashtable env = new Hashtable();
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(javax.naming.Context.PROVIDER_URL, "ldap://localhost:389");
env.put(javax.naming.Context.SECURITY_AUTHENTICATION, "simple");
env.put(javax.naming.Context.SECURITY_PRINCIPAL, "username");
env.put(javax.naming.Context.SECURITY_CREDENTIALS, "password");
env.put("java.naming.ldap.version","3");
DirContext ctx = new InitialDirContext(env);
This just simply will not work in the Servlet, and breaks at the point of
trying to create the Initial Context. Does anyone know of any known issues
with this, we've found nothing to indicate this? Workarounds? What am I
doing wrong? Any help would be HUGELY appreciated!
Regards
Mike Bartlett
cata...@eye2eye.net wrote:
> 200: javax.naming.NoInitialContextException: Cannot instantiate class:
> com.sun.jndi.ldap.LdapCtxFactory. Root exception is
> java.lang.ClassNotFoundException: com/sun/jndi/ldap/LdapCtxFactory
<snip>
> This just simply will not work in the Servlet, and breaks at the point of
> trying to create the Initial Context. Does anyone know of any known issues
> with this, we've found nothing to indicate this? Workarounds? What am I
> doing wrong? Any help would be HUGELY appreciated!
I've never been able to work out why, but I believe JNDI needs to be in
the original classpath for the JVM - letting it get loaded by
classloaders in servlets doesn't work, apparently :( I've seen this
problem in JServ and Tomcat, and am almost pleased to hear it happens
elsewhere - it means it's less likely to be something I'm doing wrong!
If you can, put jndi.jar, ldap.jar and providerutil.jar in the
jre/lib/ext directory of the VM. It saves a fair amount of hassle :) If
you can't do that, modify the startup classpath to include them all.
Hope this helps.
--
Jon Skeet - sk...@pobox.com
http://www.pobox.com/~skeet