Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM - Maven build cannot resolve dependencies when imported

brendanf9753525
Level 4
Level 4

Hi all,

I am trying to add a 3rd party library to our AEM java project. This project is build in Maven. My Maven build runs successfully, but when I import it in AEM, it crashes and cannot find dependencies that come with said 3rd party.

My question is about my build. I included the 3rd party library as a dependency,

<dependency>

<groupId>com.fasterxml.jackson.dataformat</groupId>

<artifactId>jackson-dataformat-xml</artifactId>

<version>2.9.0</version>

</dependency>

and even add the .jar file as an <Embed-Dependency> package in the pom with <embed-transitive> set.

<Embed-Transitive>true</Embed-Transitive>

<Embed-Dependency>jackson-dataformat-xml;scope=compile|runtime<Embed-Dependency>

This embeds the 3rd party .jar file into my AEM bundle build.

1468742_pastedImage_2.png

1468743_pastedImage_4.png

When I import this package and install into AEM, my bundle doesn't start and shows the below error, which basically says that all the dependencies for my 3rd party library cannot be resolved.

I attempted to fix this by adding the extra dependencies under <Import-Package> right below the <Embed-Dependency>

<Import-Package>

com.fasterxml.jackson.*,

org.codehaus.stax2.*,

</Import-Package>

1468719_pastedImage_0.png

After investigating in the bundles I saw that these bundles are indeed being loaded and even show up in the Maven Manifest MF, but AEM doesn't count them as "Imported Packages", despite them showing up under "Import-Package". They are all clearly there under the Import-Package, correct version and all but AEM does not resolve any of them.

1468720_pastedImage_1.png

Is there something else AEM needs to run these correctly? I didn't set a version that they should load but, it seems to me that since they are showing up with the correct version AEM is looking for under "Import-Package" that they would be there somewhere.

Any ideas for Maven + AEM builds would definitely help!

Thanks

Brendan

1 Accepted Solution
brendanf9753525
Correct answer by
Level 4
Level 4

This was fixed for me by also adding it under the <export-package> part of the POM.

In total I had to to 3 things to embed a 3rd party library.

1. Add standard Maven Dependency

<dependency>

<groupId>com.fasterxml.jackson.dataformat</groupId>

<artifactId>jackson-dataformat-xml</artifactId>

<version>2.9.0</version>

</dependency>

2. Embed Dependency and Import Package

<Embed-Transitive>true</Embed-Transitive>

<Embed-Dependency>jackson-dataformat-xml;scope=compile|runtime</Embed-Dependency>

<Import-Package>

com.fasterxml.jackson.*,

org.codehaus.stax2.*,

javax.inject*;version=0.0.0,*;

</Import-Package>

3. Export packages that are also in import-package

<Export-Package>com.fasterxml.jackson.*, org.codehaus.stax2.*</Export-Package>

This works and was found by me just following a few examples. While this works, I'm still a bit unsure of why it works.

Does anybody know why I have to export something if I import it? What is the difference between "import and export" that AEM can tell?

View solution in original post

4 Replies
brendanf9753525
Correct answer by
Level 4
Level 4

This was fixed for me by also adding it under the <export-package> part of the POM.

In total I had to to 3 things to embed a 3rd party library.

1. Add standard Maven Dependency

<dependency>

<groupId>com.fasterxml.jackson.dataformat</groupId>

<artifactId>jackson-dataformat-xml</artifactId>

<version>2.9.0</version>

</dependency>

2. Embed Dependency and Import Package

<Embed-Transitive>true</Embed-Transitive>

<Embed-Dependency>jackson-dataformat-xml;scope=compile|runtime</Embed-Dependency>

<Import-Package>

com.fasterxml.jackson.*,

org.codehaus.stax2.*,

javax.inject*;version=0.0.0,*;

</Import-Package>

3. Export packages that are also in import-package

<Export-Package>com.fasterxml.jackson.*, org.codehaus.stax2.*</Export-Package>

This works and was found by me just following a few examples. While this works, I'm still a bit unsure of why it works.

Does anybody know why I have to export something if I import it? What is the difference between "import and export" that AEM can tell?

View solution in original post

AdobeID24
Level 6
Level 6

Need to create manifest.mf file manually... And jar Jackson u downloaded manually? Or

just need to add dependency in pom. Xml then embed tag with import and export tag......

Maven will do all downloading the jar file and deploying in aem when we do mvn clean isntall -PautoInstallPackage

tadijam47062732
Level 3
Level 3

Jackson dependencies are part of OSGi and should not be added as embed dependency. Please, correct me if I am wrong.

I had a similar problem and figure out that there is already imported jackson dependency in intelliJ and I was overriding it with added jackson version.

Please check External Dependencies in your IDE:

Screenshot 2019-10-20 at 18.12.58.png

Please make sure that all of those are defined with the same version. In my case, I have changed all jackson dependencies in pom.xml on 2.8.11 and it all worked fine without embedding.

AdobeID24
Level 6
Level 6

had similar issue not with the jackson but with com.opencsv......