javaazureazure-blob-storageanylogicazure-java-sdk

Azure Java SDK V12 - How to fix BlobServiceClientBuilder error: "java.lang.NoClassDefFoundError: com/azure/core/client/traits/TokenCredentialTrait"


I am running an AnyLogic Cloud model with a Blob Storage connection function for sending data to Azure Blob Storage.

I'm encountering an error at runtime when attempting to call the 'BlobServiceClientBuilder' method:

import com.azure.storage.blob.*;
import com.azure.storage.blob.models.*;
import java.io.*;


BlobServiceClient serviceClient = new BlobServiceClientBuilder()
        .connectionString(<storageConnectionString>)
        .buildClient();

// I've also tried:
BlobServiceClient serviceClient = new BlobServiceClientBuilder()
        .endpoint(<endpointString>)
        .connectionString(<storageConnectionString>)
        .buildClient();

With a valid storageConnectionString and endpointString for the storage account.

The error I'm getting at runtime is the following:

java.lang.NoClassDefFoundError: com/azure/core/client/traits/TokenCredentialTrait

Given that I'm not trying to use SAS Tokens or credentials, and have opted for the connection string method (according to the Azure BlobServiceClientBuilder() documentation), I'm not sure what is causing the error.

Ideas that could be related:

Any suggestions would be greatly appreciated. I've seen a few posts here that are similar but have not been a solution for me - hoping this doesn't get a tonne of 'Duplicate' comments, but there we go!


Solution

  • The class BlobServiceClientBuilder belongs to the package com.azure.storage.blob and implements TokenCredentialTrait interface (among other things). This interface belongs to another package com.azure.core.client.traits.

    It seems like you only included the JAR file for Microsoft Azure client library for Blob Storage but not the JAR file for Microsoft Azure Java Core Library.

    Please keep in mind, that AnyLogic doesn't automatically search for and download the dependencies for external libraries. So you need to check the dependencies in the documentation and include all required JARs in your AnyLogic model.