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
- 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.
- 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.
- 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.
- Maven Bundle plugin : https://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html
- Sling Maven Plugin : https://sling.apache.org/components/sling-maven-plugin/plugin-info.html
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.
ReplyDeletemodular workstation noida
office chair in noida
Thanks for the detailed explanation! I was facing the ClassNotFound error in my project, and this solution with maven-bundle-plugin worked perfectly.
ReplyDeletecafeteria-furniture noida
Shrink wrapping machine delhi
This is exactly what I needed! The step-by-step guide and the commands were spot on. Keep up the good work!
ReplyDeletemetal storage system in noida
Box Wrapping machine delhi
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.
ReplyDeleteShrink Packing machine Delhi
Strapping machine in delhi
This post cleared up all the confusion about including both direct and transitive dependencies. I appreciate the detailed examples!
ReplyDeletefranchise Expo
Dust Collector
This tutorial was really helpful in resolving the NoClassDefFoundError. The mvn clean package install command saved me a lot of time.
ReplyDeletesaw Palmetto Oil Manufacturer in Germany
Office Furniture manufacturer noida
The step of using sling-maven-plugin for installing the bundle directly to Felix console was a game changer for me. Thanks for sharing!
ReplyDeleteWarehouse Storage rack Delhi
mezzanine floor Delhi
Can you explain how to handle version conflicts with third-party dependencies when using this approach? That would be really useful!
ReplyDeletemobile compactor in delhi
fifo flow rack manufacturer
Awesome guide! The explanation about separating bundles for future use was especially insightful. Thanks for sharing!
ReplyDeleteheavy duty rack delhi
Multi tier rack
This is exactly the solution I was looking for to integrate AEM with third-party APIs like Box. Very clear instructions!
ReplyDeleteFabric Roll Racks in Delhi
Warehouse mezzzanine floor delhi
I was struggling to include dependencies in the OSGi bundle. Your solution with maven-bundle-plugin worked like a charm. Thanks a lot!
ReplyDeleteSlotted Angle rack delhii
Modular Mezzanine floor
I love how you’ve included the GitHub link to the complete example. It made the implementation much easier to replicate.
ReplyDeletePallet rack manufacturer
Industrial Storage Rack Delhi
Great post! I’m using AEM 6.5, and this approach helped me create the OSGi bundle without any issues.
ReplyDeletePallet Rack delhi
Heavy Duty Rack Delhi
Is it possible to use the same approach for Maven-based projects other than AEM? Could you provide some examples?
ReplyDeletewarehouse storage rack delhi
Dust Collector in Delhi
This tutorial saved me a lot of debugging time. The detailed steps and error-free command examples were perfect.
ReplyDeleteAxial Flow Fans in delhi
Dust Collector Manufacturer
This was very helpful. I had a lot of trouble finding proper documentation for using the maven-bundle-plugin with third-party dependencies.
ReplyDeletePulse jet Dust Collector manufacturer
pulse jet bag filter India