因此,我正在尝试在 java 中实现 LDAP 连接...这需要 com.sun.jndi.ldap.LdapCtxFactory
。 Jarfinder 显示 LdapCtxFactory
应该包含在 rt.jar
中,根据我的理解,它是 java SDK 的基础。 Eclipse 找不到它(我正在尝试导入它)。
我之前遇到过类似的问题,但我通过安装包含它的 jar 解决了它......现在我非常困惑,因为它包含的 jar 是默认的 jar ?
注意 这也是 Android 项目的一部分。这会有什么不同吗?
编辑
我使用这个包的地方如下:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapHost);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, user + "@" + domain);
env.put(Context.SECURITY_CREDENTIALS, pass);
稍后我使用哈希表创建上下文:
ctxGC = new InitialLdapContext(env, null);
因此,由于我没有 com.sun
,因此无法在哈希表中提供它。我什至需要第一行吗?我不完全确定它的用途...
最佳答案
Eclipse 使用 its concept of "access rules". 隐藏了不属于核心 Java API 一部分的特定于实现的类您可以覆盖它,但这样做很危险。例如,我非常怀疑 Sun 实现不会在 Android 设备上可用。
相反,只需创建一个 initial context of the right type,并让框架找到正确的实现来支持它:
LdapContext ctx = new InitialLdapContext();
try {
/* Use the context... */
} finally {
ctx.close();
}
关于java - 当它应该在 rt.jar 中时,为什么我没有这个类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7824232/