Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Cannot resolve imported package in servlet bundle

Avatar

Level 1

I am trying to use a 3rd party project (Jsoup) in my servlet. I have gone through the steps to build and deploy a bundle fragment plugin as outlined here:

https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

This part works fine, I deploy it successfully via web console bundles and it has an "active" status. In my servlet's pom.xml I then include the dependency as such:

<dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.8.1</version>
</dependency>

I then build my servlet, do the maven clean install and deploy the servlet via the web console bundles. However, under imported packages I keep getting this error :

org.jsoup,version=[1.8,2) -- Cannot be resolved
org.jsoup.safety,version=[1.8,2) -- Cannot be resolved

Can anybody please help me out, its driving me nuts! Any advice would be appreciated

1 Accepted Solution

Avatar

Correct answer by
Level 10

The only thing that could possibly impact you is the version. You loaded version x and your bundle is looking for another version.

In the article, the bundle uses this version

<dependency>

           <!-- jsoup HTML parser library @ http://jsoup.org/ -->

            <groupId>org.jsoup</groupId>

            <artifactId>jsoup</artifactId>

            <version>1.7.3</version>

        </dependency>

You have to make sure that you place the same version in another bundle and deploy first. 

You can open the Manifest file in the OSGi bundle and remove version information:

Manifest-Version: 1.0
Bnd-LastModified: 1428330920949
Build-Jdk: 1.7.0_67
Built-By: scottm
Bundle-Description: Maven Multimodule project for aem.
Bundle-ManifestVersion: 2
Bundle-Name: aem Bundle
Bundle-SymbolicName: com.adobe.cq.jsoup.jsoupservice-bundle
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: com.adobe.cq.jsoup;uses:="org.jsoup,org.jsoup.select,org
 .jsoup.nodes,org.slf4j,org.osgi.framework,org.osgi.service.component";v
 ersion="1.0.0.SNAPSHOT"
Import-Package: org.jsoup,org.jsoup.nodes,org.jsoup.select,org.osgi.framework,org.osgi.service.component,org.slf4j
Service-Component: OSGI-INF/serviceComponents.xml
Tool: Bnd-1.50.0

 

 Notice that version is removed. Now I can place the bundle into an Active state.

Also look at the article referenced in this thread. The AEM JSOUP app is now attached to the article.       

View solution in original post

10 Replies

Avatar

Employee Advisor

Hi,

when you have deployed jsoup as a fragment bundle (which you attached the system bundle) you don't need to add a dependency to it. I am wondering why to deployed the jsoup package as a fragment bundle to the OSGI container instead providing the jsoup JAR as a regular bundle.

kind regards,
Jörg

Avatar

Level 10

YOu are missing the JSOUP JAR in the OSGi container. You need to place the JSOUP JAR into an OSGi bundle, deploy to AEM, and place into an active state.

Here is an AEM community article that works with JSOUP - your exact use case:

https://helpx.adobe.com/experience-manager/using/html-parser-service.html

Remember that all third party JAR files that your custom AEM services use must be loaded into an OSGi bundle,deployed, and placed into an active state. 

Avatar

Level 1

Thanks for the reply, much appreciated. I have followed the steps outlined but the problem is still not resolved. I have done the export process on the jsoup jar and loaded the OSGi bundle fragment into AEM as per the instructions. This part works the fine. The 3rd party jar is in active state in AEM. The problem is that for some reason my servlet bundle does not pick it up once I upload it to AEM...

Avatar

Level 10

Hi Chris,

Please make sure the jsoup bundle you have deployed on OSGi follows the same artifacts and version.

<dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.8.1</version>
</dependency>

Also, add the <scope>provided</scope> to the dependency and see if it helps

Avatar

Correct answer by
Level 10

The only thing that could possibly impact you is the version. You loaded version x and your bundle is looking for another version.

In the article, the bundle uses this version

<dependency>

           <!-- jsoup HTML parser library @ http://jsoup.org/ -->

            <groupId>org.jsoup</groupId>

            <artifactId>jsoup</artifactId>

            <version>1.7.3</version>

        </dependency>

You have to make sure that you place the same version in another bundle and deploy first. 

You can open the Manifest file in the OSGi bundle and remove version information:

Manifest-Version: 1.0
Bnd-LastModified: 1428330920949
Build-Jdk: 1.7.0_67
Built-By: scottm
Bundle-Description: Maven Multimodule project for aem.
Bundle-ManifestVersion: 2
Bundle-Name: aem Bundle
Bundle-SymbolicName: com.adobe.cq.jsoup.jsoupservice-bundle
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: com.adobe.cq.jsoup;uses:="org.jsoup,org.jsoup.select,org
 .jsoup.nodes,org.slf4j,org.osgi.framework,org.osgi.service.component";v
 ersion="1.0.0.SNAPSHOT"
Import-Package: org.jsoup,org.jsoup.nodes,org.jsoup.select,org.osgi.framework,org.osgi.service.component,org.slf4j
Service-Component: OSGI-INF/serviceComponents.xml
Tool: Bnd-1.50.0

 

 Notice that version is removed. Now I can place the bundle into an Active state.

Also look at the article referenced in this thread. The AEM JSOUP app is now attached to the article.       

Avatar

Level 1

Works like a charm thanks a lot for the help! The problem was with the import-package/export-package section. I appreciate the help and effort

Avatar

Level 10

I will setup a connect session with you. The reply I give you at top is correct. You are loading incorrect version. I will help you through that. 

Avatar

Level 2

HI,

 

I followed exactly same as you specified in the  document. But I still getting below error.  In my bundle I added dependency as 

 

         <dependency>
            <!-- jsoup HTML parser library @ http://jsoup.org/ -->
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.7.3</version>
        </dependency>

 

When I ran the maven command In menifest file I am seeing import and 

The Import-package section is have the version number as below.  Could you please help how can I fix this issue.

 

Import-Package: com.adobe.cq.sightly;version="[2.5,3)",com.day.cq.i18n;v
 ersion="[5.4,6)",com.day.cq.wcm.api;version="[1.17,2)",com.day.cq.wcm.a
 pi.designer;version="[5.8,6)",com.day.cq.wcm.msm.api;version="[5.9,6)",
 com.delltechnologies.constants,com.delltechnologies.service,javax.injec
 t;version=1,javax.jcr;version="[2.0,3)",javax.jcr.observation;version="
 [2.0,3)",javax.servlet,org.apache.commons.lang3;version="[3.0,4)",org.a
 pache.commons.lang3.builder;version="[3.0,4)",org.apache.sling.api;vers
 ion="[2.3,3)",org.apache.sling.api.request;version="[2.4,3)",org.apache
 .sling.api.resource;version="[2.9,3)",org.apache.sling.api.scripting;ve
 rsion="[2.2,3)",org.apache.sling.commons.json;version="[2.0,3)",org.apa
 che.sling.commons.osgi;version="[2.4,3)",org.apache.sling.jcr.api;versi
 on="[2.3,3)",org.jsoup;version="[1.7,2)",org.jsoup.nodes;version="[1.7,
 2)",org.jsoup.select;version="[1.7,2)
",org.osgi.service.component;versi
 on="[1.1,2)",org.slf4j;version="[1.5,2)"

g.jsoup,version=[1.7,2) -- Cannot be resolved
org.jsoup.safety,version=[1.7,2) -- Cannot be resolved

Avatar

Employee

you need to install jsoup jar also as a bundle , just faced this problem and then installed Maven Repository: org.jsoup » jsoup » 1.10.3  , worked for me.