LDAP库的Maven依赖关系无法在OSGi中解决

时间:2019-07-10 13:46:00

标签: maven osgi aem

我正在尝试导入

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;

并使用

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

在父pom和

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

在捆绑包pom中。

问题是

- 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

目标-我正在尝试连接LDAP

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

参考-LDAP Connection documentation

2 个答案:

答案 0 :(得分:3)

您必须区分构建时间运行时依赖项。在Maven中,您定义构建时间依赖项。默认情况下,它们与无关与AEM中安装的捆绑软件无关(运行时依赖项)。

为清楚起见:

  

在Maven中定义的依赖项不是不是自动安装到AEM中。

有几种方法可以部署所需的运行时依赖于AEM:

  1. 手动安装(/system/console/bundles
  2. 将它们放入内容包中,然后手动部署该内容包。
  3. 扩展您的Maven构建以创建一个内容包,其中包含您在运行时所需的包(例如org.apache.directory.api:api-ldap-client-api:2.0.0.AM4
  4. 使用AEM的install目录在硬盘上安装捆绑软件:crx-quickstart/install

所有这些都有优点和缺点。我通常选择选项#3。我在这里写了一个冗长的答案,解释了这一点:https://stackoverflow.com/a/56698917/190823

答案 1 :(得分:0)

如果您不需要它们,可以通过执行以下操作将它们排除在该部分中:

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

以此类推。

相关问题