Embedding our jar file into OSGI bundle fails. | Community
Skip to main content
Level 6
June 25, 2023
Solved

Embedding our jar file into OSGI bundle fails.

  • June 25, 2023
  • 5 replies
  • 5821 views

 

hi folks

I am trying to embed one of our java client libraries into AEM.

 

I followed:

https://www.linkedin.com/pulse/how-add-third-party-bundle-you-aem-package-veena-vikraman/

 

in ui.apps, I created an "install" directory with the client lib ( which was converted into a OSGi bundle)

In content-package-maven-plugin, I added "embeddeds" and "embedded" and added the  group, artifact id and the target directory.

 

in aem.core,for "maven-bundle-plugin" I added the artifact id to the Embed-Dependency list.

 

 I added Dependencys to aem.core and the parent pom.xmls... with scope of "provided".

 

However I got these errors. Am I missing some step?

 

thanks.

Fiona

 

[WARNING] The POM for com.xxx.xxx-api-client-jdk8:jar:1.20.0-SNAPSHOT is missing, no dependency information available

 

:[ERROR] Failed to execute goal on project aem.core: Could not resolve dependencies for project com.xxxx.aem.core:bundle:1.0.0-SNAPSHOT: Could not find artifact com.xx.xxxx-api-client-jdk8:jar:1.20.0-SNAPSHOT -> [Help 1]

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by sudheersundalam1

Hi fionas,

I have similar restriction in my project with a third-party jar which is not available to download via maven dependency.

Here is what I did and it's working perfectly with cloud manager deployments.

- Using maven local repository concept and create a local repo within the project structure and commit it as part of your codebase.

- Refer the local repo within the main pom.xml under the <repositories> section.

- Add the third party jar as any other maven dependency using the <dependency> tag.

- Export the classes of your jar file using <plugin> --> maven-bundle-plugin --> <_exportcontents> tag.

 

Checkout the screenshots to get a idea.

 

Thanks,

Sudheer.

5 replies

aanchal-sikka
Community Advisor
Community Advisor
June 26, 2023

Hello @fionas76543059 

 

jar to bundle conversion:

- When we convert a jar to bundle, we need to make sure that the Manifest file has proper exports.

- The easiest way to convert a jar to bundle is to use bnd tool. It can be downloaded from http://www.java2s.com/Code/Jar/b/Downloadbndjar.htm

- Once downloaded, execute following command 

Command: 

java -jar bnd.jar wrap <your_jar>.jar

- A file will be generated, change its extension to .jar

 

Deploying bundle to AEM: Multiple approaches

  1. Using artifactory like Jfrog. You would need to add the bundle to artifactory and configure pom.xml of your project to download the dependency from artifactory .
  2. Using the install folder as suggested on How to add a third party bundle to your AEM package ? (linkedin.com)

Key is to get your jar->bundle right first

 

Aanchal Sikka
Sady_Rifat
Community Advisor
Community Advisor
June 26, 2023

Hello @fionas76543059 ,

The process you followed should work for an OSGI-ready jar. But some jar files are not installed in OSGI by this process. You can follow this documentation to install your jar file into OSGI. https://myaemlearnings.blogspot.com/2021/08/embedding-third-party-dependencyosgi.html 

 

For this, you need to add an extra module, I Hope this will help you. 

 

 

Level 6
June 26, 2023

Thanks for all the suggestions.

 

Our API code is proprietary, not in a public repo, and  our company repository is not contactable for the Adobe pipelines.

 

I am hoping that when I install the OSGi bundle that I have made from my code, that the Adobe pipeline will put the code into its /root/.m2/repository to be available as a dependency to compile the code in "core"

 

I wonder does the order of the modules matter?

 

 

Sady_Rifat
Community Advisor
Community Advisor
June 26, 2023

I don't think so. I tried both ways to embed that additional module before and after the core module. Yes, both times it runs fine. 

Community Advisor
June 26, 2023

@fionas76543059 

The method you are following should work. Did you add the dependency in apps pom.xml where you are actually trying to embed it?

 

sudheersundalam1Accepted solution
Level 2
June 26, 2023

Hi fionas,

I have similar restriction in my project with a third-party jar which is not available to download via maven dependency.

Here is what I did and it's working perfectly with cloud manager deployments.

- Using maven local repository concept and create a local repo within the project structure and commit it as part of your codebase.

- Refer the local repo within the main pom.xml under the <repositories> section.

- Add the third party jar as any other maven dependency using the <dependency> tag.

- Export the classes of your jar file using <plugin> --> maven-bundle-plugin --> <_exportcontents> tag.

 

Checkout the screenshots to get a idea.

 

Thanks,

Sudheer.

Level 6
June 26, 2023

Thank you!

 

That looks interesting. I will give it a try

Nupur_Jain
Adobe Employee
Adobe Employee
June 27, 2023

Hi @fionas76543059 

 

You can embed the jar using the following way:

  • In AEMasCS project/ archetype project with version >= 24, OSGi bundle out of core module is embedded in all module as opposed to ui.apps module (Old project structure)
  •  Add dependency for third party jar in all pom.xml
  • Add <embedded> tag for dependency jar in <embeddeds> section of filevault-package-maven-plugin of all pom.xml like this
     
    <embedded>
        <groupId>GROUP_IDd>
        <artifactId>ARTIFACT_ID</artifactId>
        <target>/apps/myproject-packages/content/install</target>
    </embedded>

  • The build will add the jar file on the above mentioned path in repository and jar will be treated as an OSGI bundle

Thanks,

Nupur

Level 6
June 30, 2023

Thanks everyone for your great feedback.

Actually I gave up in the end  and manually copied over the files from the API into my project.

But I learned a lot about OSGi and will make another attempt some other time!