Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

AWS package cannot be resolved by Felix Console

Avatar

Level 2

Hi guys,

I am using the most recent maven archtype and therefore have the following folder structure:

Project Name

-Core

-it.launcher

-it.tests

-it.apps

-ui.content

I am importing an AWS dependency on my Master POM and Core POM

Master POM

<dependencyManagement>

   <dependencies>

   <!--AWS Dependencies -->
   <dependency>

   <groupId>software.amazon.awssdk</groupId>

   <artifactId>bom</artifactId>

   <version>2.5.25</version>

   <type>pom</type>

   <scope>import</scope>

   </dependency>

   <dependency>

   <groupId>com.amazonaws</groupId>

   <artifactId>aws-java-sdk-cloudfront</artifactId>

   <version>1.11.534</version>

   </dependency>

Core POM

<dependencies>

   <!--AWS Dependency -->
   <dependency>

   <groupId>com.amazonaws</groupId>

   <artifactId>aws-java-sdk-cloudfront</artifactId>

   </dependency>

The class using the AWS functionality is a custom workflow step that I have put inside the Core folder. However, when I deploy this to AEM I am getting "Cannot be resolved". I understand that just simply adding the dependency to the POM only helps compiling the code however the OSGI container is not able to see the dependency.

Screenshot from 2019-04-15 16-27-35.png

How can I fix this in my current project structure? I've read a few comments telling us to create some sort of eclipse bundle, but is there a more practical way to sort out this issue? We need this to be part of our continuous integration pipeline.

Many thanks in advance

1 Accepted Solution

Avatar

Correct answer by
Level 2

Ok, I finally managed to get it to work! It was based on Macdonalds original advice.

For all reading this, ignore the <artifactId>aws-java-sdk-osgi</artifactId> bundle because it has a lot of dependency faults and version issues. You will end up driving yourself mad chasing dependencies. For anyone wanting to incorporate AWS related stuff DO NOT follow the AWS tutorial here Using the SDK with Apache Maven - AWS SDK for Java  it will tell you to either install the "bom" package or the one that pulls all the dependencies <groupId>software.amazon.awssdk</groupId>. I just used the bit that interested me which was cloudfront, so I used the following dependency:

            <dependency>

                <groupId>com.amazonaws</groupId>

                <artifactId>aws-java-sdk-cloudfront</artifactId>

                <version>1.11.534</version>

            </dependency>

Then using that dependency only, I created a bundle in eclipse following the link Macdonald provided me Adobe Experience Manager Help | Submitting Adobe Experience Manager form data to Java Sling Servlets

The jar you need to build the bundle can be found in your .m2 folder.

It is very important that you remove all manifest related information from the bundle otherwise you will run into version problems.

Then deploy it to OSGI using the update button.

It should look something like this:

Bundle-Name: AWS-Cloudfront-AEM-Centrica-OSGI

Bundle-SymbolicName: AWS-Cloudfront-AEM-Centrica-OSGI

Bundle-Version: 1.0.0

Bundle-Vendor: Centrica

Automatic-Module-Name: AWS-AEM-Centrica-OSGI

Bundle-RequiredExecutionEnvironment: JavaSE-1.8

Export-Package: com.amazonaws, etc... etc... etc...

If you get the "cannot be resolved"  issue regarding any of the things I mention in the printscreens above, DO NOT CHASE THEM you will end up going down a rabit hole.

Thanks to all that tried to help and especially, huge thanks Macdonald!!!

View solution in original post

19 Replies

Avatar

Level 10

Include  "bom" and "aws-java-sdk-cloudfront"  in Embed-Dependency

example:

<plugin>

<groupId>org.apache.felix</groupId>

<artifactId>maven-bundle-plugin</artifactId>

<extensions>true</extensions>

<configuration>

<instructions>

<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>

<Bundle-Name>${project.name}</Bundle-Name>

<Embed-Dependency>bom,aws-java-sdk-cloudfront,*;scope=compile</Embed-Dependency>

<Import-Package>*</Import-Package>

</instructions>

</configuration>

</plugin>

If that doesn't work, please share your pom.xml's  maven-bundle-plugin configuration

Avatar

Level 2

Thank you so much for the prompt answer. Unfortunately it did not work. My Core Pom is as follows:

<?xml version="1.0" encoding="UTF-8"?>

<!-- | Copyright 2014 Adobe Systems Incorporated | | Licensed under the Apache

License, Version 2.0 (the "License"); | you may not use this file except

in compliance with the License. | You may obtain a copy of the License at

| | http://www.apache.org/licenses/LICENSE-2.0 | | Unless required by applicable

law or agreed to in writing, software | distributed under the License is

distributed on an "AS IS" BASIS, | WITHOUT WARRANTIES OR CONDITIONS OF ANY

KIND, either express or implied. | See the License for the specific language

governing permissions and | limitations under the License. -->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>

        <groupId>com.company</groupId>

        <artifactId>CC-aem</artifactId>

        <version>${companyCurrent}</version>

        <relativePath>../pom.xml</relativePath>

    </parent>

    <artifactId>CC-aem.core</artifactId>

    <packaging>bundle</packaging>

    <name>Comapny CMS (AEM6) - Core</name>

    <description>Core bundle for Company CMS (AEM6)</description>

    <build>

        <plugins>

            <plugin>

                <groupId>org.apache.felix</groupId>

                <artifactId>maven-scr-plugin</artifactId>

            </plugin>

            <plugin>

                <groupId>org.apache.felix</groupId>

                <artifactId>maven-bundle-plugin</artifactId>

                <extensions>true</extensions>

                <configuration>

                    <instructions>

                        <!-- <Embed-Dependency> artifactId1, artifactId2;inline=true </Embed-Dependency> -->

                    </instructions>

                </configuration>

            </plugin>

        </plugins>

    </build>

    <profiles>

        <!-- Development profile: install only the bundle -->

        <profile>

            <id>autoInstallBundle</id>

            <activation>

                <activeByDefault>false</activeByDefault>

            </activation>

            <build>

                <plugins>

                    <plugin>

                        <groupId>org.apache.sling</groupId>

                        <artifactId>maven-sling-plugin</artifactId>

                        <configuration>

                            <slingUrlSuffix>/apps/company/install/</slingUrlSuffix>

                            <failOnError>true</failOnError>

                        </configuration>

                    </plugin>

                </plugins>

            </build>

        </profile>

    </profiles>

    <dependencies>

        <!--AWS Dependency -->

        <dependency>

            <groupId>com.amazonaws</groupId>

            <artifactId>aws-java-sdk-cloudfront</artifactId>

        </dependency>

        <!-- OSGi Dependencies -->

        <dependency>

            <groupId>org.apache.felix</groupId>

            <artifactId>org.apache.felix.scr</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.felix</groupId>

            <artifactId>org.apache.felix.scr.annotations</artifactId>

        </dependency>

        <dependency>

            <groupId>biz.aQute</groupId>

            <artifactId>bndlib</artifactId>

        </dependency>

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>org.osgi.core</artifactId>

        </dependency>

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>org.osgi.compendium</artifactId>

        </dependency>

        <!-- Other Dependencies -->

        <dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>slf4j-api</artifactId>

        </dependency>

        <dependency>

            <groupId>javax.jcr</groupId>

            <artifactId>jcr</artifactId>

        </dependency>

        <dependency>

            <groupId>javax.servlet</groupId>

            <artifactId>servlet-api</artifactId>

        </dependency>

        <dependency>

            <groupId>com.adobe.aem</groupId>

            <artifactId>aem-api</artifactId>

        </dependency>

        <dependency>

            <groupId>junit</groupId>

            <artifactId>junit</artifactId>

        </dependency>

        <dependency>

            <groupId>org.mockito</groupId>

            <artifactId>mockito-all</artifactId>

        </dependency>

        <dependency>

            <groupId>junit-addons</groupId>

            <artifactId>junit-addons</artifactId>

        </dependency>

        <dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>slf4j-log4j12</artifactId>

            <!-- the binding version needs to match the slf4j api -->

            <version>1.5.11</version>

            <scope>test</scope>

        </dependency>

        <dependency>

            <groupId>org.projectlombok</groupId>

            <artifactId>lombok</artifactId>

            <version>1.18.6</version>

            <scope>provided</scope>

        </dependency>

    </dependencies>

</project>

Avatar

Level 10

Try getting the JARs that expose these packages and wrap them into an OSGi bundle and deploy to AEM. That way - you know for sure these Java Packages are in the OSGi service container.

Avatar

Level 2

Thank you Macdonald! How do I do that with my Core bundle?

Thanks

Avatar

Level 10

The nice thing about AEM is you can build an OSGi bundle that contains dependent JARS separate from your project. Any OSGi bundle that contains AWS JARs will resolve these Java packages for any OSGi bundle that requires them.

One way to build an OSGi bundle that contains other JARS is documented here - notice how we wrap the SIMPLE JSON JAR into a bundle.

Adobe Experience Manager Help | Submitting Adobe Experience Manager form data to Java Sling Servlets

Avatar

Level 2

Thanks Macdonald. I have done that and now I can see the dependency in the depfinder:

Screenshot from 2019-04-17 11-47-33.png

The problem is my project still can't find those dependencies:

Screenshot from 2019-04-17 11-50-11.png

My POM currently looks like this:

<build>

   <plugins>

   <plugin>

   <groupId>org.apache.felix</groupId>

   <artifactId>maven-scr-plugin</artifactId>

   </plugin>

   <plugin>

   <groupId>org.apache.felix</groupId>

   <artifactId>maven-bundle-plugin</artifactId>

   <extensions>true</extensions>

   <configuration>

   <instructions>

   </instructions>

   </configuration>

   </plugin>

   </plugins>

</build>

If I add the following to the POM instructions in the POM

<build>

   <plugins>

   <plugin>

   <groupId>org.apache.felix</groupId>

   <artifactId>maven-scr-plugin</artifactId>

   </plugin>

   <plugin>

   <groupId>org.apache.felix</groupId>

   <artifactId>maven-bundle-plugin</artifactId>

   <extensions>true</extensions>

   <configuration>

   <instructions>

   <Embed-Dependency>aws-java-sdk-osgi,*;scope=compile</Embed-Dependency>

   <Import-Package>com.amazonaws.*,*</Import-Package>

   </instructions>

   </configuration>

   </plugin>

   </plugins>

</build>

I get even more errors... Does this mean I need to wrap those extra dependencies to my project bundle I created separately? Kinda feels like I am going down a rabbit hole haha

Or are the instructions to the pom not the correct one? Help....

Screenshot from 2019-04-17 12-17-28.png

Screenshot from 2019-04-17 12-17-37.png

Avatar

Level 10

For com.fasterxml.* packages, install OSGIfied bundles from Maven Repository: Search/Browse/Explore

for org.springframework.*, aspectj.*, joda.* use Spring DM bundles and install in OSGI

for org.apache.http.*, update maven-bundle-plugin to import it dynamically from AEM-OOB -- use org.apache.httpcomponents.httpcore

for netty, use OSGIfied bundle

for amazon.*, either use OSGIfied bundles or package them into your code bundle  using Embed-Dependency as mentioned above

Avatar

Level 2

What do you mean by OSGified bundles?

Avatar

Level 10

I meant OSGI bundles and not that jar files (you'd find both versions on web in mvnrepository and other sites)

Avatar

Level 2

Mate the bundles are already there... I don't have to install them again. I can find them through the depfinder

Screenshot from 2019-04-17 15-48-28.png

Problem is they cannot be resolved... Same happens to the AWS packages. I followed Macdonalds advice and created a bundle that exports them, but for some reason they are not picked up.

Avatar

Level 10

If a bundle is already available/active in OSGI say com.fasterxml.jackson.annotation then add its symbolic name to maven-bundle-plugin in your pom.xml and test it

<Require-Bundle>com.fasterxml.jackson.annotation</Require-Bundle>

Alternatively, you could also package the jar/bundle within your code-bundle so that it resolves using internally available classes as Scott mentioned -- use <Import-Package>.... </Import-Package> for same

Avatar

Community Advisor

Hi Filip,

What's the problem with using [0], this one has been adapted for OSGi, so you don't have to mess with the dependencies yourself:

[0] Maven Repository: com.amazonaws » aws-java-sdk-osgi

Regards,

Peter

Avatar

Level 2

Thanks Peter!

That's the dependency I am using as well in the Core POM.

I tried it before but when I install that dependency on OSGI though I get these errors:

Screenshot from 2019-04-17 16-22-55.png

Avatar

Community Advisor

Hi Filip,

For the dependencies that can't be resolved by your Apache Felix OSGi context, you would either set them as ignored in your OSGi context or help AWS bundle to resolve these by having them present in your OSGi system.

Regards,

Peter

Avatar

Correct answer by
Level 2

Ok, I finally managed to get it to work! It was based on Macdonalds original advice.

For all reading this, ignore the <artifactId>aws-java-sdk-osgi</artifactId> bundle because it has a lot of dependency faults and version issues. You will end up driving yourself mad chasing dependencies. For anyone wanting to incorporate AWS related stuff DO NOT follow the AWS tutorial here Using the SDK with Apache Maven - AWS SDK for Java  it will tell you to either install the "bom" package or the one that pulls all the dependencies <groupId>software.amazon.awssdk</groupId>. I just used the bit that interested me which was cloudfront, so I used the following dependency:

            <dependency>

                <groupId>com.amazonaws</groupId>

                <artifactId>aws-java-sdk-cloudfront</artifactId>

                <version>1.11.534</version>

            </dependency>

Then using that dependency only, I created a bundle in eclipse following the link Macdonald provided me Adobe Experience Manager Help | Submitting Adobe Experience Manager form data to Java Sling Servlets

The jar you need to build the bundle can be found in your .m2 folder.

It is very important that you remove all manifest related information from the bundle otherwise you will run into version problems.

Then deploy it to OSGI using the update button.

It should look something like this:

Bundle-Name: AWS-Cloudfront-AEM-Centrica-OSGI

Bundle-SymbolicName: AWS-Cloudfront-AEM-Centrica-OSGI

Bundle-Version: 1.0.0

Bundle-Vendor: Centrica

Automatic-Module-Name: AWS-AEM-Centrica-OSGI

Bundle-RequiredExecutionEnvironment: JavaSE-1.8

Export-Package: com.amazonaws, etc... etc... etc...

If you get the "cannot be resolved"  issue regarding any of the things I mention in the printscreens above, DO NOT CHASE THEM you will end up going down a rabit hole.

Thanks to all that tried to help and especially, huge thanks Macdonald!!!

Avatar

Level 1

HI  tonycarreira ,

I am trying out same solution you got it. Can I get the proper link address whih you used  given by  Macdonald . Because the link provided  by you doesnot work anymore.

Can you please send me the proper link from Mt  Macdonald .

Avatar

Level 1

Hi @Baysunny,

 

Could you please send me the proper link from Mt  Macdonald.

I am also facing the same issue.

 

Avatar

Level 3

Funny how things work out. Now i am part of the AWS team after working on AEM for 7 years.

Avatar

Level 1

Hi Mr Scott,  I am  trying to download a file from AWS S3 bucket via AEM backend code in a seperate workflow process step.

I am unable to get the bundle resolved when I use various AWS API dependencies.

 

I tried using the dependency jar as below:

 

<dependency>
   <groupId>com.amazonaws</groupId>
   <artifactId>aws-java-sdk-osgi</artifactId>
   <scope>provided</scope>
</dependency>

 

Error we are getting in ISGI bundle here is :

 

Imported Packages

com.fasterxml.jackson.annotation,version=[2.12,3) -- Cannot be resolved
com.fasterxml.jackson.core,version=[2.12,3) -- Cannot be resolved
com.fasterxml.jackson.core.type,version=[2.12,3) -- Cannot be resolved
com.fasterxml.jackson.databind,version=[2.12,3) -- Cannot be resolved
com.fasterxml.jackson.databind.annotation,version=[2.12,3) -- Cannot be resolved
com.fasterxml.jackson.databind.deser.std,version=[2.12,3) -- Cannot be resolved
com.fasterxml.jackson.databind.module,version=[2.12,3) -- Cannot be resolved
com.fasterxml.jackson.databind.node,version=[2.12,3) -- Cannot be resolved
com.fasterxml.jackson.databind.ser.std,version=[2.12,3) -- Cannot be resolved
com.fasterxml.jackson.databind.type,version=[2.12,3) -- Cannot be resolved
com.fasterxml.jackson.dataformat.cbor,version=[2.12,3) -- Cannot be resolved
io.netty.bootstrap,version=[4.1,5) -- Cannot be resolved
io.netty.buffer,version=[4.1,5) -- Cannot be resolved
io.netty.channel,version=[4.1,5) -- Cannot be resolved
io.netty.channel.nio,version=[4.1,5) -- Cannot be resolved
io.netty.channel.socket.nio,version=[4.1,5) -- Cannot be resolved
io.netty.handler.codec -- Cannot be resolved
io.netty.handler.codec.http,version=[4.1,5) -- Cannot be resolved
io.netty.handler.logging,version=[4.1,5) -- Cannot be resolved
io.netty.handler.ssl,version=[4.1,5) -- Cannot be resolved
io.netty.handler.stream,version=[4.1,5) -- Cannot be resolved
io.netty.util,version=[4.1,5) -- Cannot be resolved
io.netty.util.concurrent,version=[4.1,5) -- Cannot be resolved

 

 

Can you please help to resolve it with proper AWS API dependecy to use and how to resolve the bundle in felix console by providing the corect link address.

 

Thanks