AWS package cannot be resolved by Felix Console

tonycarreira 15-04-2019

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

Accepted Solutions (1)

Accepted Solutions (1)

tonycarreira 18-04-2019

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!!!

Answers (15)

Answers (15)

PuzanovsP
MVP
17-04-2019

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

tonycarreira 17-04-2019

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

gauravb41175071
MVP
17-04-2019

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

tonycarreira 17-04-2019

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.

gauravb41175071
MVP
17-04-2019

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

tonycarreira 17-04-2019

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

smacdonald2008 16-04-2019

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

smacdonald2008 16-04-2019

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.

tonycarreira 16-04-2019

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>

gauravb41175071
MVP
15-04-2019

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