ERREUR: vous Devez spécifier le nom de la classe dans l'environnement ou de la propriété du système LDAP et JNDI

C'est mon code:

     public class TestConnection {

public static void main(String[] args) {
    String password = "s3cret";
    Map<String, String> env = new HashMap<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://localhost:389/dc=userdev,dc=local");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    //env.put(Context.SECURITY_PRINCIPAL, "uid="+ username +"cn=users"); //replace with user DN
    env.put(Context.SECURITY_PRINCIPAL, "cn=dcmanager,cn=users,dc=userdev,dc=local"); //replace with user DN
    env.put(Context.SECURITY_CREDENTIALS, password);

    DirContext ctx = null;
    try {
       ctx = new InitialDirContext();
    } catch (NamingException e) {
       //handle
    }
    try {
       SearchControls controls = new SearchControls();
       controls.setSearchScope( SearchControls.SUBTREE_SCOPE);
       ctx.search( "", "(objectclass=person)", controls);
       //no need to process the results
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        System.out.println("catch 1");
       //The base context was not found.
       //Just clean up and exit.
    } catch (NamingException e) {
        System.out.println("catch 2");
        e.printStackTrace();
       //exception handling
    } finally {
       //close ctx or do Java 7 try-with-resources http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
    }

}

    }

J'ai eu cette erreur (capture 2) :
javax.de nommage.NoInitialContextException: Besoin de spécifier le nom de la classe dans l'environnement ou de la propriété du système, ou comme une applet paramètre, ou dans une ressource d'application fichier: java.de nommage.usine.initiale

J'ai regardé pour un tas de solutions, mais je n'ai pas l'erreur.
Où est le problème?
Peut-être que le contexte, mais je pense que le code est parfaitement correcte.

OriginalL'auteur user840718 | 2014-06-19