Java – why don’t I own this class when it should be in rt.jar?
So, I'm trying to implement LDAP connection in Java... This requires com sun. jndi. ldap. LdapCtxFactory. Jarfinder shows that ldapctxfactory should be included in rt.jar. As far as I know, it is the basis of Java SDK Eclipse can't find it (I'm trying to import it)
I have a similar problem, but I solve it by installing the jar containing it Now I'm very confused because the jar it contains is the default jar?
Please note that this is also part of the Android project Will this make a difference?
edit
The places where I am using this package are as follows:
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);
Then I use the hash table to create the context:
ctxGC = new InitialLdapContext(env,null);
So, because I don't have com Sun, I can't provide it in the hash table Do I need the front line? I'm not exactly sure what it is
Solution
Eclipse hides the implementation - specific class its concept of "access rules" that does not belong to the core Java API You can overwrite it, but it's dangerous For example, I strongly doubt that the sun implementation will be available on Android devices
Instead, just create an initial context of the right type and let the framework find the correct implementation to back it up:
LdapContext ctx = new InitialLdapContext(); try { /* Use the context... */ } finally { ctx.close(); }