Create/build and install OSGi bundle of third party APIs/dependency using maven plugins

This post details the steps to create and deploy OSGI bundle out of third party API/dependency using relevant plugins in simple maven project.

We would have been in situation where OSGi bundle created out of third party jar is added/available in our instance and our project code base using the third party bundle being in active state. However at the time of execution, ClassNotFound or NoClassDefFound error pops up.

This is the case when the dependencies of our desired third party API is not included/available when it is added as an OSGi bundle.

We can overcome this by creating the bundle using maven-bundle-plugin which has option to include

  • direct(desired third party dependency - highlighted in red in below screenshot - 
    • * -  to include all the dependency entry in the pom.xml file or 
    • artifactId name if we would like to mention explicitly 
    • Note : There are several other possible options documented for <Embed-Dependency> in official plugin page (Mentioned the link at the end in Reference section)
  • transitive dependencies (dependencies which our third party API is dependent on - highlighted in green in below screenshot is responsible for the same)


With this plugin information in the <build> tag + third party dependency of our interest in <dependencies> section along with details like group id, artifact id in pom.xml file will help create OSGi bundle using the command - mvn package or mvn clean package

Next, to install the created bundle directly to felix console, we can make use of a plugin named sling-maven-plugin which has properties to specify

  • AEM instance felix console URL(as highlighted in green in below screenshot) + 
  • username and password details(mentioned in <properties> as <sling.user> and <sling.password> respectively) 
  • Note: One of its goal named install is used for installing the bundle to felix console. Official plugin page is mentioned at the end in Reference section.

Updated command to use : mvn clean package install


To demonstrate with specific example, I would like to pick Box API as third party dependency which was recently raised in our community forum. Link to the thread for reference - https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/integrate-aem-with-box-com-to-store-completed-forms/qaq-p/396609

Below highlighted dependency information from Maven central for Box Java SDK is used.


Complete pom.xml file is added to my GitHub repo - https://github.com/Viji1304/aemlearnings-samples/tree/master/BOXSDK

Steps to try in your local:
  • Download the folder from above location
  • Update the instance port, user name and password per your local instance in pom.xml file and with dependency of your interest. 
  • Execute mvn clean package install  from cmd by being in pom.xml file location
  • Look for the bundle in target folder and in your local instance felix console.
As a standalone bundle: 
Based on our real time project set up + per the functionality expected out of 3rd party APIs, 

  • We can choose to have this as a separate project and hence separate bundle if you have many projects/bundle which might make use of in future or
  • If you have common code base which all other projects are making use of, this can be included as part of the same.
As part of project code base:
  • If your project's core module makes use of maven-bundle-plugin, it will work on the similar lines as explained above where desired third party dependency is added to main pom.xml and core/pom.xml + highlighted instructions in screenshot above of maven-bundle-plugin is used.
  • In recent AEM Maven archetype version, bnd-maven-plugin is used to build OSGi bundle out of core module wherein instruction named -conditionalpackage is suggested to use for the similar purpose. However, I couldn't gain success in this case for one of the third party API that I tried in my local, will update once it works.
Reference:

Comments

  1. Great post! It was really helpful in understanding how to integrate third-party APIs using OSGi bundles in AEM. The screenshots made it easy to follow along.
    modular workstation noida
    office chair in noida

    ReplyDelete
  2. Thanks for the detailed explanation! I was facing the ClassNotFound error in my project, and this solution with maven-bundle-plugin worked perfectly.
    cafeteria-furniture noida
    Shrink wrapping machine delhi

    ReplyDelete
  3. This is exactly what I needed! The step-by-step guide and the commands were spot on. Keep up the good work!
    metal storage system in noida
    Box Wrapping machine delhi

    ReplyDelete
  4. Excellent post! The link to the Box API thread was especially useful for my current project. It helped me integrate Box SDK with AEM smoothly.
    Shrink Packing machine Delhi
    Strapping machine in delhi

    ReplyDelete
  5. This post cleared up all the confusion about including both direct and transitive dependencies. I appreciate the detailed examples!
    franchise Expo
    Dust Collector

    ReplyDelete
  6. This tutorial was really helpful in resolving the NoClassDefFoundError. The mvn clean package install command saved me a lot of time.
    saw Palmetto Oil Manufacturer in Germany
    Office Furniture manufacturer noida

    ReplyDelete
  7. The step of using sling-maven-plugin for installing the bundle directly to Felix console was a game changer for me. Thanks for sharing!
    Warehouse Storage rack Delhi
    mezzanine floor Delhi

    ReplyDelete
  8. Can you explain how to handle version conflicts with third-party dependencies when using this approach? That would be really useful!
    mobile compactor in delhi
    fifo flow rack manufacturer

    ReplyDelete
  9. Awesome guide! The explanation about separating bundles for future use was especially insightful. Thanks for sharing!
    heavy duty rack delhi
    Multi tier rack

    ReplyDelete
  10. This is exactly the solution I was looking for to integrate AEM with third-party APIs like Box. Very clear instructions!
    Fabric Roll Racks in Delhi
    Warehouse mezzzanine floor delhi

    ReplyDelete
  11. I was struggling to include dependencies in the OSGi bundle. Your solution with maven-bundle-plugin worked like a charm. Thanks a lot!
    Slotted Angle rack delhii
    Modular Mezzanine floor

    ReplyDelete
  12. I love how you’ve included the GitHub link to the complete example. It made the implementation much easier to replicate.
    Pallet rack manufacturer
    Industrial Storage Rack Delhi

    ReplyDelete
  13. Great post! I’m using AEM 6.5, and this approach helped me create the OSGi bundle without any issues.
    Pallet Rack delhi
    Heavy Duty Rack Delhi

    ReplyDelete
  14. Is it possible to use the same approach for Maven-based projects other than AEM? Could you provide some examples?
    warehouse storage rack delhi
    Dust Collector in Delhi

    ReplyDelete
  15. This tutorial saved me a lot of debugging time. The detailed steps and error-free command examples were perfect.
    Axial Flow Fans in delhi
    Dust Collector Manufacturer

    ReplyDelete
  16. This was very helpful. I had a lot of trouble finding proper documentation for using the maven-bundle-plugin with third-party dependencies.
    Pulse jet Dust Collector manufacturer
    pulse jet bag filter India

    ReplyDelete

Post a Comment

Popular posts from this blog

Embedding Third party dependency/OSGi bundle in AEM application hosted in AEMasCS

OSGI Factory Configuration implementation

Embed Third party dependency using bnd-maven-plugin