How to use third party api in AEM | Community
Skip to main content
Level 2
October 20, 2022

How to use third party api in AEM

  • October 20, 2022
  • 1 reply
  • 4030 views

Hi everyone,

 

I'm new to aem and is still learning based on the training project adobe provided.

I try to create a new servlet so i can upload file to AWS s3 bucket, but it returns build error and i don't know how to solve it so really prefer some help.

 

build error message:

 

Here is what i added into the pom file.

pom.xml

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-osgi</artifactId>
    <version>1.12.322</version>
</dependency>
 
core/pom.xml
<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-osgi</artifactId>
</dependency>
 
I also download the newest aws-java-sdk-osgi jar file and installed it through web console.But the status is installed and when i try to start the bundle it returns the error below.

 

error log:

[FelixLogListener]
LogService.org.apache.felix.http.jetty Bundles: Cannot start (org.apache.felix.log.LogException: org.osgi.framework.BundleException: Unable to resolve com.amazonaws.aws-java-sdk-osgi [586](R 586.0): missing requirement [com.amazonaws.aws-java-sdk-osgi [586](R 586.0)] osgi.wiring.package; (&(osgi.wiring.package=com.fasterxml.jackson.dataformat.cbor)(version>=2.12.0)(!(version>=3.0.0))) Unresolved requirements: [[com.amazonaws.aws-java-sdk-osgi [586](R 586.0)] osgi.wiring.package; (&(osgi.wiring.package=com.fasterxml.jackson.dataformat.cbor)(version>=2.12.0)(!(version>=3.0.0)))])
org.apache.felix.log.LogException: org.osgi.framework.BundleException: Unable to resolve com.amazonaws.aws-java-sdk-osgi [586](R 586.0): missing requirement [com.amazonaws.aws-java-sdk-osgi [586](R 586.0)] osgi.wiring.package; (&(osgi.wiring.package=com.fasterxml.jackson.dataformat.cbor)(version>=2.12.0)(!(version>=3.0.0))) Unresolved requirements: [[com.amazonaws.aws-java-sdk-osgi [586](R 586.0)] osgi.wiring.package; (&(osgi.wiring.package=com.fasterxml.jackson.dataformat.cbor)(version>=2.12.0)(!(version>=3.0.0)))]

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

1 reply

Level 4
October 20, 2022

Hi @zonghuiliu ,

 

This is caused if the package imported is not exported by any bundle. The Import-Package declarations must be satisfied by the Export-package declaration of other included bundles in the Maven project.

 

To solve this add the package in the Export tag 

If your archetype is using maven-bundle-plugin then use the below in your pom.xml 

 

<Export-Package>

com.amazonaws.aws-java-sdk-osgi.*

</Export-Package>

 

If your archetype is using bnd-maven-plugin then use the below in your pom.xml

 

Export-Package: com.amazonaws.aws-java-sdk-osgi.*

 

 

Reference:

https://myaemlearnings.blogspot.com/2021/08/embedding-third-party-dependencyosgi.html

 

 

Level 2
October 20, 2022

Thank you for your reply.

 

I'm using bnd-maven-plugin but i still have no idea where to add the export package.

Below is how i made the change.

I'm sorry for this newbie question but could you please tell me the right place to add the export package description.

 

pom.xml

<!-- BND Maven Plugin -->
                       
        <plugin>
                             
          <groupId>biz.aQute.bnd</groupId>                  
          <artifactId>bnd-maven-plugin</artifactId>                  
          <version>${bnd.version}</version>              
          <executions>                    
            <execution>                      
              <id>bnd-process</id>                  
              <goals>                        
                <goal>bnd-process</goal>                    
              </goals>                    
              <configuration>                          
                <bnd>
                  <![CDATA[
Bundle-Category: ${componentGroupName}
Export-Package: com.amazonaws.aws-java-sdk-osgi.*

# export all versioned packages except for conditional ones (https://github.com/bndtools/bnd/issues/3721#issuecomment-579026778)
-exportcontents: ${removeall;${packages;VERSIONED};${packages;CONDITIONAL}}

-noextraheaders: true
-snapshot: SNAPSHOT

Bundle-DocURL:
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin
-plugin org.apache.sling.bnd.models.ModelsScannerPlugin
                                ]]>
                </bnd>
                                           
              </configuration>
                                     
            </execution>
                               
          </executions>
                             
          <dependencies>
                                   
            <dependency>
                                         
              <groupId>org.apache.sling</groupId>
                                         
              <artifactId>org.apache.sling.caconfig.bnd-plugin</artifactId>
                                         
              <version>1.0.2</version>
                                     
            </dependency>
                                   
            <dependency>
                                         
              <groupId>org.apache.sling</groupId>
                                         
              <artifactId>org.apache.sling.bnd.models</artifactId>
                                         
              <version>1.0.0</version>
                                     
            </dependency>
                                   
            <dependency>
                                         
              <groupId>org.apache.sling</groupId>
                                         
              <artifactId>scriptingbundle-maven-plugin</artifactId>
                                         
              <version>0.5.0</version>
                                     
            </dependency>
                               
          </dependencies>
                         
        </plugin>
 
core/pom.xml
 
<plugin>
                <groupId>biz.aQute.bnd</groupId>
                <artifactId>bnd-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>bnd-process</id>
                        <goals>
                            <goal>bnd-process</goal>
                        </goals>
                        <configuration>
                            <bnd><![CDATA[
Import-Package: javax.annotation;version=0.0.0,*
Export-Package: com.amazonaws.aws-java-sdk-osgi.*
                                ]]></bnd>
                                <instructions>
                    </instructions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Level 2
October 24, 2022

@zonghuiliu 

It's correct.

You can keep it in only core/pom.xml.


Sorry for the late reply.

 

I've made the change to core/pom.xml and still got the same error.

I've read this tutorial Embed Third party dependency using bnd-maven-plugin (myaemlearnings.blogspot.com) but cannot find any description about export package.

 

Do i have to add the aws-java-sdk-osgi jar file into the project folder and where should i put it?Or is there anything i missed to do.

 

Thank you  for your help in advance.