7

I am trying to use Spring LDAP for coding

<ldap-server ldif="classpath:my-ldap-clone.ldif" />

but I get this error

NoClassDefFoundError: org/apache/directory/server/core/DirectoryService

What am I doing wrong?

Didier L
  • 18,905
  • 10
  • 61
  • 103
SJS
  • 5,607
  • 19
  • 78
  • 105

3 Answers3

13

Using maven :

    <dependency>
        <groupId>org.apache.directory.server</groupId>
        <artifactId>apacheds-all</artifactId>
        <version>1.5.7</version>
    </dependency>
foa
  • 319
  • 2
  • 5
  • 4
    I doubt it is a good idea to add that big dependency (10MB!) if you need only a fraction of it. For instance, spring-security-ldap requires only 5 jars, see here : http://mvnrepository.com/artifact/org.springframework.security/spring-security-ldap/3.2.3.RELEASE – Charles Morin Apr 15 '14 at 13:32
  • I have the same error. I'm new to Maven, but shouldn't dependencies be downloaded by Maven automatically? Why does this need to be specified explicitly in my app's pom.xml? Thanks! – Tamara Aviv Dec 05 '16 at 17:38
5

If you are using Maven, these actually come from an optional dependency of spring-security-ldap.

Using apacheds-all is a bad idea because it embeds a lot of rather common dependencies, like slf4j and dom4j. You would easily get into classloader issues with it.

Instead, you should look inside the pom of the spring-security-ldap version your are using, for the apacheds optional dependencies, and copy them over to your pom without the <scope> and <optional> elements (unfortunately there is no better way to handle optional dependencies with Maven).

For instance, with spring-security-ldap 4.2.2, it would give:

<dependency>
    <groupId>org.apache.directory.server</groupId>
    <artifactId>apacheds-core</artifactId>
    <version>1.5.5</version>
</dependency>
<dependency>
    <groupId>org.apache.directory.server</groupId>
    <artifactId>apacheds-core-entry</artifactId>
    <version>1.5.5</version>
</dependency>
<dependency>
    <groupId>org.apache.directory.server</groupId>
    <artifactId>apacheds-protocol-ldap</artifactId>
    <version>1.5.5</version>
</dependency>
<dependency>
    <groupId>org.apache.directory.server</groupId>
    <artifactId>apacheds-protocol-shared</artifactId>
    <version>1.5.5</version>
</dependency>
<dependency>
    <groupId>org.apache.directory.server</groupId>
    <artifactId>apacheds-server-jndi</artifactId>
    <version>1.5.5</version>
</dependency>

(it looks like it hasn't changed since at least 3.2)

Didier L
  • 18,905
  • 10
  • 61
  • 103
2

Download ApcheDS from below link http://directory.apache.org/ or get complete jar from here I have used to work with Spring Security 3.0.5 with LDAP (Spring LDAP 1.3). That time i didn't met requirement of ApacheDS. Check your version of Spring Secuirty which may have dependency with ApacheDS.

Senthil
  • 5,514
  • 2
  • 22
  • 11