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

Embedding external jar is not working in AEMaaCS

Avatar

Level 9

 

I want to add aws-sdk-java jar as part of code deployment in AEMaaCS hence I am using embed feature to add external jar but the jar file is not including during build in /apps/myproject-packages/application/install location.
 
Used embed in <project>\all module

 

<plugin>
	<groupId>org.apache.jackrabbit</groupId>
	<artifactId>filevault-package-maven-plugin</artifactId>
	<extensions>true</extensions>
	<configuration>
		<group>com.myproject.aem</group>
		<packageType>container</packageType>
		<!-- skip sub package validation for now as some vendor packages like CIF apps will not pass -->
		<skipSubPackageValidation>true</skipSubPackageValidation>
		<embeddeds>
			<embedded>
				<groupId>com.myproject.aem</groupId>
				<artifactId>aem-myproject.ui.apps</artifactId>
				<type>zip</type>
				<target>/apps/myproject-packages/application/install</target>
			</embedded>
			<embedded>
				<groupId>com.myproject.aem</groupId>
				<artifactId>aem-myproject.core</artifactId>
				<target>/apps/myproject-packages/application/install</target>
			</embedded>
			<embedded>
				<groupId>com.myproject.aem</groupId>
				<artifactId>aem-myproject.ui.config</artifactId>
				<type>zip</type>
				<target>/apps/myproject-packages/application/install</target>
			</embedded>
			<embedded>
				<groupId>com.myproject.aem</groupId>
				<artifactId>aem-myproject.ui.content</artifactId>
				<type>zip</type>
				<target>/apps/myproject-packages/content/install</target>
			</embedded>

			<!-- external jar-->
			<embedded>
				<groupId>software.amazon.awssdk</groupId>
				<artifactId>aws-sdk-java</artifactId>
				<target>/apps/myproject-packages/application/install</target>
			</embedded>
		</embeddeds>
	</configuration>
</plugin>

 

Added aws-sdk-java dependency in  <project>\all module as below 

 

<dependency>
	<groupId>software.amazon.awssdk</groupId>
	<artifactId>aws-sdk-java</artifactId>
</dependency>

 

Added below in dependency in parent module

 

<dependency>
	<groupId>software.amazon.awssdk</groupId>
	<artifactId>aws-sdk-java</artifactId>
	<version>2.19.33</version>
	<scope>provided</scope>
</dependency>

 

I have refered below articles - 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi @Mario248 ,

 

I think you need to create an OSGi bundle of the non-OSGi JAR dependencies, you can do it using the maven-bundle-plugin where you would also need to set the export as well.

 

Check the below article, it has a similar use case as yours.

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

 

Hope that helps!

 

Regards,

Nitesh

View solution in original post

14 Replies

Avatar

Community Advisor

Hi @Mario248 

The above steps look fine but I didn't see the dependency used in the core module where you want to use the corresponding classes. You might need to add the dependency in the core module pom.xml along with the parent pom.

<dependency>
	<groupId>software.amazon.awssdk</groupId>
	<artifactId>aws-sdk-java</artifactId>
</dependency>


Also, If you still see the issue, can you share the screenshot of the system/console/bundle where we can see the error?

Regards,

Arpit Varshney

Avatar

Level 9

I have already adde this in core module dependency. Sorry, I forgot to mention this before. 

 

I see below error while deploying to AEM,

 

Could not start bundle aem-myproject.core [622]. Reason: {}. Will retry.
org.osgi.framework.BundleException: Unable to resolve aem-myproject.core [622](R 622.69 missing requirement [aem-myproject.core [622](R 622.69)] osgi.wiring.package; (osgi.wiring.package=software.amazon.awssdk.auth.credentials) Unresolved requirements: [[aem-myproject.core [622](R 622.69)] osgi.wiring.package; (osgi.wiring.package=software.amazon.awssdk.auth.credentials)]
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4368)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2281)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984)
at org.apache.sling.installer.core.impl.tasks.BundleStartTask.execute(BundleStartTask.java:97) [org.apache.sling.installer.core:3.9.0.B002]
at org.apache.sling.installer.core.impl.OsgiInstallerImpl.doExecuteTasks(OsgiInstallerImpl.java:914) [org.apache.sling.installer.core:3.9.0.B002]
at org.apache.sling.installer.core.impl.OsgiInstallerImpl.executeTasks(OsgiInstallerImpl.java:749) [org.apache.sling.installer.core:3.9.0.B002]
at org.apache.sling.installer.core.impl.OsgiInstallerImpl.run(OsgiInstallerImpl.java:298) [org.apache.sling.installer.core:3.9.0.B002]
at java.base/java.lang.Thread.run(Thread.java:834)
 
Seems like I need to below dependency  as well ,
 
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>auth</artifactId>
<version>2.20.2</version>
</dependency>
 
Should this be just as dependency or embed to AEM? Any suggestion ?

Avatar

Community Advisor

@Mario248 It seems like the jar you mentioned above is depending on this jar which is not resolving as a bundle. Could you please add this jar as well in all/pom.xml like the one you mentioned in the problem statement and follow the same steps for this one and see if it works?

Regards,

Arpit Varshney

Avatar

Level 9

I already used  <embedded> to include external jar except <type> attribute. I guess the default value is jar if we dont provide.

Avatar

Community Advisor

software.amazon.awssdk.auth.credentials is a jar or a bundle? if it is a jar then it will not be resolved in aem.



Arun Patidar

Avatar

Level 9

Thanks for your response. I am aware that Bundle-SymbolicName header in the MANIFEST.MF tells whether it is jar or bundle. I found that it is not osgi bundle it is just plain jar file. below is the manifest file

 

Manifest-Version: 1.0
Automatic-Module-Name: software.amazon.awssdk.awscore
Build-Jdk-Spec: 1.8
Created-By: Maven JAR Plugin 3.3.0

 

Can you tell me how we should install this jar file(https://mvnrepository.com/artifact/software.amazon.awssdk/aws-core/2.20.2) in AEM?

Avatar

Community Advisor

you need to convert jar to a bundle and host at your own artifact repository/project and then add as dependency



Arun Patidar

Avatar

Level 9

Thanks. Just want to understand this thing, I have around 40+ dependencies  in 

dependencyManagement in my parent pom like OSGi Dependencies, Adobe AEM Dependencies, Apache Sling Dependencies, Servlet API, JCR categories.
 
Mario248_0-1676297146482.png

 

 
 
Two questions
Q1 - Are all 40+ dependencies are OSGI compatible, OSGI bundle ? 
Q2 - Do I need to make sure that any external APIs and libraries I use are OSGI-compatible so that AEM can support it?

Avatar

Community Advisor

dependencies with provided/test scope are used during build/test, so does not matter if they are bundle or jar

but if you are deploying in jar in AEM webconsole must be a bundle.



Arun Patidar

Avatar

Level 9

Great, Thank you for the explanation. In my case I want to use this jar as provided if I am correct.

Basically I want to import few classes from this jar and have below logic 

 

Imports

 

import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.CreateTopicRequest;
import software.amazon.awssdk.services.sns.model.CreateTopicResponse;
import software.amazon.awssdk.services.sns.model.SnsException;

Code

 

    public static String createSNSTopic(SnsClient snsClient, String topicName ) {

        CreateTopicResponse result = null;
        try {
            CreateTopicRequest request = CreateTopicRequest.builder()
                    .name(topicName)
                    .build();

            result = snsClient.createTopic(request);
            return result.topicArn();
        } catch (SnsException e) {

            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
        return "";
    }

Reference - https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/examples-simple-notification-service...

 

I have already added below thing in my parent POM, as below(same as original question)

<dependency>
	<groupId>software.amazon.awssdk</groupId>
	<artifactId>aws-sdk-java</artifactId>
	<version>2.19.33</version>
	<scope>provided</scope>
</dependency>

 

I don't need to install this in Felix console, I can use it directly, right?

Avatar

Community Advisor

if you want to execute your code in AEM then you need this jar in Felix.
provide is used when container(Felix console) already(OOTB/manually installed) have the jar



Arun Patidar

Avatar

Community Advisor

Hi @Mario248 ,

 

 

 

If you are stuck with JAR which you want as bundle then you can just convert the JAR to bundle and then use it. Please refer below video-

 

https://youtu.be/EXyvsIknCLI

 

Thanks

Ritesh Mittal

Avatar

Correct answer by
Employee Advisor

Hi @Mario248 ,

 

I think you need to create an OSGi bundle of the non-OSGi JAR dependencies, you can do it using the maven-bundle-plugin where you would also need to set the export as well.

 

Check the below article, it has a similar use case as yours.

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

 

Hope that helps!

 

Regards,

Nitesh