Maven dependency for LDAP library could not be resolved in OSGi

天大地大妈咪最大 提交于 2021-02-05 09:31:09

问题


I am trying to import

import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.apache.directory.ldap.client.api.DefaultLdapConnectionFactory;
import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.ldap.client.api.LdapConnectionConfig;
import org.apache.directory.ldap.client.api.LdapConnectionPool;
import org.apache.directory.ldap.client.api.ValidatingPoolableLdapConnectionFactory;
import org.apache.directory.ldap.client.template.LdapConnectionTemplate;

and using

<dependency>
    <groupId>org.apache.directory.api</groupId>
    <artifactId>api-ldap-client-api</artifactId>
    <version>2.0.0.AM4</version>
</dependency>

in the parent pom and

<dependency>
    <groupId>org.apache.directory.api</groupId>
    <artifactId>api-ldap-client-api</artifactId>
</dependency>

in the bundle pom.

The issue is

- The artifact is not present in osgi after build and
- Project bundle is in resoved state due to error 

org.apache.commons.pool2,version=[2.6,3) -- Cannot be resolved
org.apache.commons.pool2.impl,version=[2.6,3) -- Cannot be resolved
org.apache.directory.ldap.client.api,version=[2.0,3) -- Cannot be resolved
org.apache.directory.ldap.client.template,version=[2.0,3) -- Cannot be resolved

UPDATED QUESTION -

"How to resolve these dependencies? Which ldap dependency/library could be used in OSGi?"

Objective - I'm trying to connect LDAP

LdapConnection connection = new LdapNetworkConnection( "localhost", 10389 );

Reference - LDAP Connection documentation


回答1:


You have to distinguish between build time and runtime dependencies. In Maven you define your build time dependencies. Per default they have nothing to do with the bundles installed in AEM (runtime dependencies).

To make it clear:

Dependencies defined in Maven are not automatically installed into AEM.

There are a few options how you can deploy the required runtime dependencies to AEM:

  1. Install them by hand (/system/console/bundles)
  2. Put them in a content package and deploy that content package by hand.
  3. Extend your Maven build to create a content-package which includes the bundles you need at runtime (e.g. org.apache.directory.api:api-ldap-client-api:2.0.0.AM4)
  4. Install the bundles using the install directory of AEM on the hard disk: crx-quickstart/install.

All of them have advantages and disadvantages. I usually opt for option #3. I have written a lengthy answer that explains this here: https://stackoverflow.com/a/56698917/190823




回答2:


If you do not require them, you can exclude them in the section, by doing something like this:

<configuration>
  <instructions>
    <Import-Package>
      !org.apache.commons.pool2,

And so on.



来源:https://stackoverflow.com/questions/56972114/maven-dependency-for-ldap-library-could-not-be-resolved-in-osgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!