title: LDAP jndi connection (java + jboss eap 6)
body: <p>i'm new to ldap and also to jndi resources and even to jboss (lol) and i'm trying to figure out how to make this working. I need to connect with an LDAP server which config is defined in Jboss standalone.xml file, and need to access it through jndi within java.</p>
  
  <p>I've defined in standalone.xml and external-context to connect with LDAP:</p>
  
  <pre><code>&lt;subsystem xmlns="urn:jboss:domain:naming:1.4"&gt;
          &lt;bindings&gt;
            &lt;external-context name="java:global/ldap" module="org.jboss.as.naming" class="javax.naming.ldap.InitialLdapContext" cache="true"&gt;
                &lt;environment&gt;
                   &lt;property name="java.naming.factory.initial" value="com.sun.jndi.ldap.LdapCtxFactory"/&gt;
                   &lt;property name="java.naming.provider.url" value="ldap://host:port"/&gt;
                   &lt;property name="java.naming.security.authentication" value="simple"/&gt;
                   &lt;property name="java.naming.security.principal" value="user"/&gt;
                   &lt;property name="java.naming.security.credentials" value="password"/&gt;
                 &lt;/environment&gt;
              &lt;/external-context&gt;
           &lt;/bindings&gt;
          &lt;remote-naming/&gt;
  &lt;/subsystem&gt;
  </code></pre>
  
  <p>Then in java i've this code:</p>
  
  <pre><code>InitialLdapContext ctx = new InitialLdapContext();
  LdapContext ldapContext = null;
  ldapContext = (LdapContext) ctx.lookup("java:global/ldap"));
  </code></pre>
  
  <p>But when the lookup executes i get the following error:</p>
  
  <pre><code>java.lang.NoSuchMethodException: javax.naming.ldap.InitialLdapContext.&lt;init&gt;(java.util.Hashtable)
  </code></pre>
  
  <p>I've tried many different examples but i can't get anything working...</p>
  
  <p>Thanks in advance.</p>