问题
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:
- Install them by hand (
/system/console/bundles
) - Put them in a content package and deploy that content package by hand.
- 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
) - 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