Expand my Community achievements bar.

Including Adobe Target SDK in Custom OSGI Bundles

Avatar

Level 4

Hello.

I have a custom OSGI bundle deployed to an AEM 6.5 instance. I wanted to include the Adobe Target Java SDK in the project (so it can be utilized by another service class).

 

I have added it to my pom.xml:

 

<dependency>
  <groupId>com.adobe.target</groupId>
  <artifactId>target-java-sdk</artifactId>
  <scope>compile</scope>
</dependency>

 

 

However, after publishing the package, I see the following error in the Web Console:

com.adobe.target.delivery.v1.model -- Cannot be resolved
com.adobe.target.edge.client.model -- Cannot be resolved

 After noting this error, I configured the maven-bundle-plugin as follows:

 

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<exportScr>true</exportScr>
<instructions>
<Embed-Dependency>target-java-sdk;scope=compile|runtime</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>

 

 

However, this led to another set of errors relating to dependencies used by the Target SDK (json-logic-java, unirest-java, etc). I added those to the `Embed-Dependency` option and then got another error for another set of dependencies.

 

So, rather than having to explicitly include an endless chain of dependencies, I am would like to know that is the recommended practice for integrating the Target SDK with AEM? Does Adobe provide OSGI bundles for the SDK?

9 Replies

Avatar

Community Advisor

Hi @KMarchewa ,

The best way to install the Adobe Target Java SDK is to embed the bundle into your. here's instructions on how to do it:

You can do this easily (after building and deploying code into your AEM local, you should be able to find the jar file existing under /apps/my-site/install:

1. Include the Adobe Target Java SDK as a dependency in the ui.apps pom.xml

<!-- Adobe Target Java SDK -->
<dependency>
<groupId>com.adobe.target</groupId>
<artifactId>target-java-sdk</artifactId>
</dependency>

2. Embed the Adobe Target Java SDK as a package for deployment in ui.apps/all pom.xml

<embedded>
<groupId>com.adobe.target</groupId>
<artifactId>target-java-sdk</artifactId>
<target>/apps/my-site/install</target>
</embedded>

3. Include the Adobe Target Java SDK as a dependency in the parent pom.xml

<!-- Adobe Target Java SDK -->
<dependency>
<groupId>com.adobe.target</groupId>
<artifactId>target-java-sdk</artifactId>
<version>2.3.0</version>
</dependency>


 Hope that helps!

Regards,
Santosh

Avatar

Level 4

Thanks much for the quick response. Unfortunately, this app does not have a `ui.apps` directory (it is a mature code base and I assume was not built using the current maven archetype). Is there an alternative for such a project? Thanks much.

Avatar

Community Advisor

@KMarchewa 
May I see your project structure? where your AEM components are present? If you have old version maven archetype please visit this article https://www.techinnovia.com/osgi-bundle-lifecycle/ in video we have described hoe to do that.

Avatar

Level 4

Sure. Please see attached.

Kazam_screenshot_00007.pngKazam_screenshot_00008.pngKazam_screenshot_00009.png

Basically, the front-end code (html, client libs, JCR related nodes/XML) is under "packages". The Java code is under "bundles" with three further subprojects of "providers", "services" and "servlets". The Target SDK is used directly in "bundles/services"; the Service class that utilizes the SDK is then consumed in a class under "bundles/providers". Both the "bundles/services" and "bundles/providers" bundles are the ones giving the error (and that I added the SDK dependency too). Hope that makes sense. Thanks!

Avatar

Community Advisor

@KMarchewa 
Just check how your "bundles" module is embedded to apps(packages) similar way you can follow rest all adding dependency will be same, the way you were following above was for external jar file so, basically.

  1. Add dependency in parent.pom xml with version
  2. Add dependency in "bundles" pom.xml
  3. Embed it to "packages".

Avatar

Level 4

Thanks but I followed the steps and I am still getting the same error. Specifically, in the parent POM I put:

```

<dependency>
<groupId>com.adobe.target</groupId>
<artifactId>target-java-sdk</artifactId>
<version>2.2.2</version>
</dependency>

```

In the "bundles/providers" and "bundles/services" POMs I added:

```

<dependency>
<groupId>com.adobe.target</groupId>
<artifactId>target-java-sdk</artifactId>
<scope>compile</scope>
</dependency>

```

 

And in `packages/application/bundle-install/pom.xml` I added:

```

<embedded>
<groupId>com.adobe.target</groupId>
<artifactId>target-java-sdk</artifactId>
<filter>true</filter>
</embedded>

```

Avatar

Community Advisor

@KMarchewa 
Can you try 

<scope>provided</scope>

instead compiled?

Avatar

Level 4

Sure, I tried that but, unfortunately, still received the error.

Avatar

Level 1

@KMarchewa  Did you find any way here for installing the Target with Custom bundles.I am also facing the same issue.