October 13, 2020
Estimated Post Reading Time ~

Resolve dependencies by converting Jar to Bundle - AEM 6.5.5

Many a times we come across such scenarios when we have to use some dependencies which are not resolved by our AEM server. In that case our project bundle doesn’t gets resolved and we see the dependency errors marked in red.

org.apache.oltu.oauth2.client,version=[1.0,2) — Cannot be resolved

In this case we will download the dependency Jar from the maven repository and convert it into OSGI bundle and deploy it to the AEM server.

Process to convert Jar to Bundle:
1. Go to File –> New –> Other –> Plug-in from existing JAR Archives



Click next and the add the JAR that we downloaded using the option Add External JAR and click next and provide the following configuration as per the requirement. And then click next and finish.


Now go to MANIFEST.MF file and remove the version from the imported packages as shown below.

Remove versions

Now switch to Runtime tab and click on add in Export packages column to add the packes and dependency that we want to export as part of this bundle. These are the same dependencies which were not getting resolved as bundle.
Exporting packages

Don’t forget to save the changes after updating the MANIFEST.MF file.

Now right click on the plugin project created in package explorer and click on Export and select Deployable plug-ins and fragments


Now provide the path where you want to save the deployable bundle locally and click on finish. Now go to the specified location and you will find the deployable bundle.

Installing directly on felix console is not the best way to resolve the dependency so we will deploy it as part of embed code.

Now create a install folder in your local code-base at ../apps/<project-name>/install/<Bundle.jar>
And now embed the code in ui.apps POM.xml

<embedded>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-solrj</artifactId>
    <target>/apps/<project-name>/install</target>
<embedded>


Now when the code is built, this bundle gets deployed on the Felix console and when we go and check the dependency it will be resolved as our project bundle is now importing the dependency from the created bundle’s exported packages.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.