I am trying to use Jsoup library by creating an OSGi bundle out of it. I have created the bundles before so I am pretty much familiar with the process. I have also added the dependencies in the pom.xml like this:
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.3</version>
</dependency>
I am also following the steps given here: https://helpx.adobe.com/experience-manager/using/html-parser-service.html
I have tried everything but still the dependencies are not getting resolved. Attached are the screenshots.
What do I do ?
Thanks in advance
There is a version mismatch. Your bundle depends on the packages org.jsoup and friends having version 1.7 or higher. Strictly speaking it imports from version 1.7.0 (inclusive) up to version 2.0.0 (exclusive).
However, the bundle installed in your runtime exports as version 0.0.0. Therefore the import does not match the available exports and your bundle cannot resolve.
It seems you need to find an org.jsoup bundle that exports as version 1.7, and install that into your runtime instead of the bundle you have used here.
There a couple of various ways to resolve your problem:
Force import 0.0.0 version exported by your Jsoup bundle. (easiest)
This can be performed by update of Import-Package section of your bundle which consumes Jsoup packages:
<Import-Package>
org.jsoup.*;resolution:=required;version="[0.0,0.1)"
</Import-Package>
Wrap your Jsoup dependency with Maven POM and set version which you would like to export via update of Export-Package section (optional):
<Export-Package>
org.jsoup.*;version="1.7.2"
</Export-Package>
Details: http://www.cqblueprints.com/tipsandtricks/build-and-deploy-osgi/deploy-third-party-libs.html
Install another Jsoup JAR as OSGi bundle.
Original Jsoup 1.7.2 (http://mvnrepository.com/artifact/org.jsoup/jsoup/1.7.2) was good in my project.
Update your Maven "dependency" item to import:
<dependency>
<groupId>com.adobe.cq.jsoup</groupId>
<artifactId>jsoupservice-bundle</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Related
Background
commons-beanutils-core version 1.8.0 has some security issues that I am trying to avoid.
So, I am using commons-beanutils 1.9.4
Problem
I cannot seem to prevent other libraries from importing commons-beanutils-core version 1.8.0. Nowhere in my pom file do I include it. I am assuming some other dependency implicitly includes it. And, since commons-beanutils-core no longer is supported and they have moved to just using commons-beanutils for all newer versions, when I explicitly write:
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
It does not remove the implicit references to commons-beanutils-core.
Question
How do I make the other packages not download commons-beanutils-core version 1.8.0?
Notes:
There have been other packages that were downloaded as dependencies that I did not explicitly include in my pom.xml. A scan show that some of these packages were security risks. So, my solution was to just explicitly include a higher version of the package that was previously included implicitly. And that removed the old version of the package. But that solution does not work here since commons-beanutils-core is no longer used in the newest version.
Update 1
I have learned that including the following code will make the pom.xml think that 1.8.0 will be provided, and in a sense it will since I will include 1.9.4. But I am unsure if the code will use the 1.9.4 if it thinks it should look for 1.8.0. This code enables me to remove 1.8.0 but I don't know if my deception here will cause problems down the line.
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils-core</artifactId>
<version>1.8.0</version>
<scope>provided</scope>
</dependency>
Using provided scope can have side effects on runtime. Provided scope dependencies are used in compilation but not packaged so if the commons-beanutils-core has a method which is not present in commons-beanutils you will get NoSuchMethodException.
Better solution will be use mvn dependency:tree to find which dependencies had dependency on commons-beanutils-core and
Either update the dependency to a version which uses 1.9.4 version of commons-beanutils.
Or use exclusion to exclude commons-beanutils-core from the dependencies using commons-beanutils-core as a dependency.
If you can use method 1 it's better if you cannot find a dependency which uses the latest version, then use method 2.
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
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
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.
In my work project, I use spark-submit to launch my application into a yarn cluster. I am quite new to Maven projects and pom.xml use, but the problem I seem to be having is that hadoop is using an older version of google protobuf (2.5.0) than the internal dependencies I'm importing at work (2.6.1).
The error is here:
java.lang.NoSuchMethodError:
com/google/protobuf/LazyStringList.getUnmodifiableView()Lcom/google/protobuf/LazyStringList;
(loaded from file:/usr/hdp/2.6.4.0-91/spark2/jars/protobuf-java-2.5.0.jar
by sun.misc.Launcher$AppClassLoader#8b6f2bf7)
called from class protobuf.com.mycompany.group.otherproject.api.JobProto$Query
Since I'm not quite sure how to approach dependency issues like this, and I can't change the code of the internal dependency that uses 2.6.1, I added the required protobuf version as a dependency to my project, as well:
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.6.1</version>
</dependency>
Unfortunately, this hasn't resolved the issue. When the internal dependency (which does import 2.6.1 on its own) tries to use its proto, the conflict occurs.
Any suggestions on how I could force the usage of the newer, correct version would be greatly appreciated.
Ultimately I found the Maven Shade Plugin to be the answer. I shaded my company's version of protobufs, deployed our service as an uber jar, and the conflict was resolved.
I am trying to transfer a gradle-based build plugin for android to a maven build system.
Up to now I was successful except with the android part.
It seems that I am missing classes from the package com.android.build.api.transform. Although I used this code
<dependency>
<groupId>com.android.tools.build</groupId>
<artifactId>gradle</artifactId>
<version>2.2.0</version>
<type>jar</type>
</dependency>
which is supposed to provide (rather indirectly) the required classes/packages, it seems that this is not working.
I also added
<repositories>
<repository>
<id>android</id>
<name>android</name>
<url>https://plugins.gradle.org/m2/</url>
</repository>
</repositories>
just in case, with no luck. Still the project is not able to compile due to missing classes.
Any idea what I am missing? I am very new to the gradle/maven scene, and I still feel out of my waters with these tools.
For reference here is a link to the javadoc of this artifact.
Thanks for your help
The 'gradle' artifact does not contain the missing package. As you mention, it depends transitively on at least one artifact that contains that package, but only in scope 'runtime'. Hence, it will not be available to your project on the compile classpath.
Anyway, adding the dependency explicitly in your pom.xml is the right thing to do. A search for the missing package on search.maven.org shows that you have the choice between com.android.tools.build:transform-api and com.android.tools.build:gradle-api. Locking at the transform-api artifact reveals that it's deprecated and encourages to use gradle-api instead. (The latest version is '2.0.0-deprecated-use-gradle-api'). I downloaded the gradle-api jar file, which indeed has the missing package. So please try adding that artifact to your pom.xml instead:
<dependency>
<groupId>com.android.tools.build</groupId>
<artifactId>gradle-api</artifactId>
<version>2.3.0</version>
</dependency>
I didn't check version 2.2.0, but if you for some reason want to use the older version, it will probably work too.
the transform API was a Google's Android Gradle plugin technology. but it was absorbed into and expanded by Gradle. so newer Android plugins migrated to the Gradle API and they no longer include the transform engine, which now is part of Gradle. if you use the deprecated transform API from Google that was bundled with older plugins, you will get the engine. but what you plan to do about all the other dependencies on Gradle, i have no idea.
I'm having a slight problem with incorporating the appropriate maven dependencies into my project for sling models.
When I deploy my bundle, I get the following import that can't be resolved:
org.apache.sling.models.annotations,version=[1.1,2) -- Cannot be resolved
I believe I have included this with the following dependencies:
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.impl</artifactId>
</dependency>
I tried using:
<Embed-Transitive>true</Embed-Transitive>
<Import-Package>*</Import-Package>
in my bundle compile instructions, but this has just resulted in a ton of other dependencies not being resolved.
Surely I've gone down the garden path here somewhere. Any help would be greatly appreciated.
The org.apache.sling.models.api V1.0.2 bundle does export the following packages:
javax.inject,version=0.0.0
org.apache.sling.models.annotations,version=1.1.0
org.apache.sling.models.annotations.injectorspecific,version=1.0.0
org.apache.sling.models.spi,version=1.0.0
org.apache.sling.models.spi.injectorspecific,version=1.0.0
So if that bundle is active in your Sling instance, the org.apache.sling.models.annotations,version=[1.1,2) import should resolve.
Note that adding bundles to your maven dependencies might not be sufficient to install them in the running instance, what matters is whether the models.api bundle is active as seen from /system/console/bundles
Using Embed-Transitive is almost always a terrible idea. It traverses the entire transitive dependency hierarchy in Maven and pulls each one of those JARs into your own JAR. As a result you inherit all the package dependencies of all that crap you have dragged in.
When you have a bundle such as yours that requires an import -- in this case org.apache.sling.models.annotations -- the best solution is to find another bundle already available that exports the same package.