java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory
Hello,
i am trying to connect our Active Directory to retrieve some user Information. When trying to get an InitialLdapContext i get the following exception:
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.jndi.ldap.LdapCtxFactory [Root exception is java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory]
at com.day.commons.simplejndi.impl.ContextService$ICFactoryBuilder.createInitialContextFactory(ContextService.java:165)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:681)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:153)
at com.company.cq.directory.LdapUtil.getInitialContext(LdapUtil.java:294)
at com.company.cq.directory.LdapUtil.getAttribute(LdapUtil.java:263)
at org.apache.jsp.apps.company.components.passwordteaser.passwordteaser_jsp._jspService(passwordteaser_jsp.java:263)
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
.......
Caused by: java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory
at org.apache.sling.commons.classloader.impl.ClassLoaderFacade.loadClass(ClassLoaderFacade.java:127)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at com.day.commons.simplejndi.impl.ContextService$ICFactoryBuilder.createInitialContextFactory(ContextService.java:162)
... 85 more
The code Looks as follows:
private LdapContext getInitialContext() throws NamingException {
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, ADMIN_NAME);
env.put(Context.SECURITY_CREDENTIALS, ADMIN_PASSWORD);
env.put(Context.PROVIDER_URL, "ldap://" + HOST + ":" + PORT);
return new InitialLdapContext(env, null);
}
Has anyone an idea why the factory class cannot be found? I am using CQ5.5.
Btw, when i execute the same code outside of CQ5 on my Windows command line (CLASSPATH=.) the code works fine.
Best Regards
Jan