【问题标题】:Maven dependency for LDAP library could not be resolved in OSGiLDAP 库的 Maven 依赖项无法在 OSGi 中解决
【发布时间】:2019-11-20 03:56:29
【问题描述】:

我正在尝试导入

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>

在捆绑包中。

问题是

- 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依赖/库 可以在 OSGi 中使用吗?”

目标 - 我正在尝试连接 LDAP

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

参考 - LDAP Connection documentation

【问题讨论】:

  • 您需要从您的依赖项中创建一个依赖项 OSGI 包(jar)并上传到 AEM sling 控制台。你可以在网上找到从 jar 转换 OSGI 包的信息。

标签: maven ldap osgi aem maven-dependency-plugin


【解决方案1】:

你必须区分 build timeruntime 依赖。在 Maven 中,您定义了 构建时间 依赖项。默认情况下,它们与安装在 AEM 中的包(runtime 依赖项)没有任何关系

说清楚:

在 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

【讨论】:

  • 了解每个 maven 依赖项不会自动安装到 OSGi 中的事实。
  • 但是 org.apache.directory.api:api-ldap-client-api:2.0.0.AM4 在手动安装时由于未解决的依赖关系而无效。有没有可以在OSGi 或者deploying it manually or with maven build 中使用的依赖项
  • @AbhishekSinha 如果您阅读了我链接的答案,我解释了如何构建包含缺少的依赖项的 LDAP 库包。
【解决方案2】:

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

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

等等。

【讨论】:

  • 它们是必需的。无法排除它们。
  • 在这种情况下尝试:
  • 导出包是定义当前bundle的包,当作为依赖添加时,可以被其他bundle使用
猜你喜欢
  • 2012-01-12
  • 1970-01-01
  • 2017-01-06
  • 1970-01-01
  • 2014-04-14
  • 2014-09-05
  • 2017-01-12
  • 1970-01-01
相关资源
最近更新 更多