无法在 OSGi 中解析 LDAP 库的 Maven 依赖性
Maven dependency for LDAP library could not be resolved in OSGi
我正在尝试导入
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
更新问题 -
"How to resolve these dependencies? Which ldap dependency/library
could be used in OSGi?"
Objective - 我正在尝试连接 LDAP
LdapConnection connection = new LdapNetworkConnection( "localhost", 10389 );
您必须区分 构建时间 和 运行时间 依赖关系。在 Maven 中,您定义 构建时间 依赖项。默认情况下,它们与 AEM 中安装的捆绑包 没有任何关系(运行时 依赖项)。
说清楚:
Dependencies defined in Maven are not automatically installed into AEM.
有几个选项可以让您部署 AEM 所需的运行时 依赖项:
- 手动安装 (
/system/console/bundles
)
- 将它们放入内容包中并手动部署该内容包。
- 扩展您的 Maven 构建以创建一个 content-package,其中包括您在运行时需要的包(例如
org.apache.directory.api:api-ldap-client-api:2.0.0.AM4
)
- 使用硬盘上 AEM 的
install
目录安装捆绑包:crx-quickstart/install
.
它们都有优点和缺点。我通常选择选项#3。我在这里写了一个冗长的答案来解释这一点:
如果您不需要它们,您可以在该部分中排除它们,方法如下:
<configuration>
<instructions>
<Import-Package>
!org.apache.commons.pool2,
以此类推
我正在尝试导入
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
更新问题 -
"How to resolve these dependencies? Which ldap dependency/library could be used in OSGi?"
Objective - 我正在尝试连接 LDAP
LdapConnection connection = new LdapNetworkConnection( "localhost", 10389 );
您必须区分 构建时间 和 运行时间 依赖关系。在 Maven 中,您定义 构建时间 依赖项。默认情况下,它们与 AEM 中安装的捆绑包 没有任何关系(运行时 依赖项)。
说清楚:
Dependencies defined in Maven are not automatically installed into AEM.
有几个选项可以让您部署 AEM 所需的运行时 依赖项:
- 手动安装 (
/system/console/bundles
) - 将它们放入内容包中并手动部署该内容包。
- 扩展您的 Maven 构建以创建一个 content-package,其中包括您在运行时需要的包(例如
org.apache.directory.api:api-ldap-client-api:2.0.0.AM4
) - 使用硬盘上 AEM 的
install
目录安装捆绑包:crx-quickstart/install
.
它们都有优点和缺点。我通常选择选项#3。我在这里写了一个冗长的答案来解释这一点:
如果您不需要它们,您可以在该部分中排除它们,方法如下:
<configuration>
<instructions>
<Import-Package>
!org.apache.commons.pool2,
以此类推