0
votes

I'm trying to write a custom class in ACS Commons' MCP Tool

Including "azure storage" api in "pom.xml" as below:

<dependency>
  <groupId>com.microsoft.azure</groupId>
  <artifactId>azure-storage</artifactId>
  <version>8.0.0</version>
</dependency>

The build runs fine without any compile errors, but while running the program i'm seeing the below in error logs:

Sample usage:

import com.microsoft.azure.storage.CloudStorageAccount;
..
public class AzureAssetIngestor extends AssetIngestor {
  private CloudStorageAccount storageAccount;
  ..
  storageAccount = CloudStorageAccount.parse(storageConnectionString);

Error in logs while executing the program

Caused by: java.lang.ClassNotFoundException: com.microsoft.azure.storage.CloudStorageAccount not found by com.adobe.acs.acs-aem-commons-bundle

Caused by: java.lang.ClassNotFoundException: com.microsoft.azure.storage.CloudStorageAccount not found by com.adobe.acs.acs-aem-commons-bundle [521]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1574)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

Appreciate any help!

2

2 Answers

1
votes

There are two types of dependencies for AEM projects:

  1. Compile time dependencies
  2. Runtime dependencies

In Maven you define compile time dependencies. So adding dependencies to your pom.xml will make them available only during the build (compile time) by Maven.

It is your job as a developer to make sure that those dependencies are also available during runtime. There are basically three ways to achieve that:

  1. Install those dependencies by hand
  2. Add those dependencies to a content package that is deployed during your build
  3. Embed the dependency to your bundle during build time

It is probably obvious, but you should go with option 2 or 3. Both approaches have their advantages and disadvantages. A (relatively) big issue with option 2 is that not all your dependencies are OSGi bundles. Therefore, for this to work, you would need to transform them to OSGi bundles. This is no rocket science but another thing to keep in mind. Embedding your dependency is easier but I personally do not like that solution that much.

0
votes

With @Jens inputs, the option to install bundles manually helped/worked.

Here's the solution:

pom.xml

<artifactId>maven-bundle-plugin</artifactId>
  <Import-Package>
    com.microsoft.azure.*;resolution:=optional,
  ...
  </Import-Package>
...
<dependency>
  <groupId>com.microsoft.azure</groupId>
  <artifactId>azure-storage</artifactId>
  <version>8.0.0</version>
  <scope>provided</scope>
</dependency>

Then go to AEM Bundles (Like http://localhost:4502/system/console/bundles) to install bundles manually. You can use either of the below.

Option 1:

  1. Install Oak Blob Cloud Azure bundle. The bundle comes embedded with Azure-Storage 5.0.0 package

Option 2:

  1. Install Apache Service Mix - Download bundle Azure Storage 8.0.0. This has Azure-Storage 5.0.0 embedded. but has the below dependencies.
  2. Guava 20 - Download bundle guava-20.0.jar (Dependency for 1)
  3. Jackson Core - Download bundle jackson-core-2.9.3.jar (Dependency for 1)