Unable to create Azure BlobContainerClient as I am getting a java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/TSFBuilder

Viewed 3913

I am facing an error while trying to create a Azure blobConatinerClient using the credentials I have.

credentials is instanceOf StorageSharedKeyCredential and endpoint is instanceOf String

This is the code

 public BlobContainerClient initBlobClient() {
    BlobContainerClient blobContainerClient;

    StorageSharedKeyCredential credential = new StorageSharedKeyCredential(ACCOUNT_NAME, ACCOUNT_KEY);

    String endpoint = String.format(Locale.ROOT, "https://test.blob.core.windows.net");

// Getting the ClassDefError here
    BlobServiceClient storageClient = new BlobServiceClientBuilder().endpoint(endpoint).credential(credential).buildClient();

    blobContainerClient = storageClient.getBlobContainerClient(CONTAINTER_NAME);

    return blobContainerClient;
  }

and this is the stacktrace this triggers

    at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:122)
    at com.azure.core.util.serializer.JacksonAdapter.<init>(JacksonAdapter.java:76)
    at com.azure.core.util.serializer.JacksonAdapter.createDefaultSerializerAdapter(JacksonAdapter.java:109)
    at com.azure.core.http.rest.RestProxy.createDefaultSerializer(RestProxy.java:615)
    at com.azure.core.http.rest.RestProxy.create(RestProxy.java:667)
    at com.azure.storage.blob.implementation.ServicesImpl.<init>(ServicesImpl.java:58)
    at com.azure.storage.blob.implementation.AzureBlobStorageImpl.<init>(AzureBlobStorageImpl.java:216)
    at com.azure.storage.blob.implementation.AzureBlobStorageBuilder.build(AzureBlobStorageBuilder.java:93)
    at com.azure.storage.blob.BlobServiceAsyncClient.<init>(BlobServiceAsyncClient.java:108)
    at com.azure.storage.blob.BlobServiceClientBuilder.buildAsyncClient(BlobServiceClientBuilder.java:109)
    at com.azure.storage.blob.BlobServiceClientBuilder.buildClient(BlobServiceClientBuilder.java:82)

And these are azure dependencies I have. I also added Jackson, since one of the StackOverflow comments said that would solve the issue but it didn't.

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>2.12.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.azure/azure-storage-blob -->
    <dependency>
      <groupId>com.azure</groupId>
      <artifactId>azure-storage-blob</artifactId>
      <version>12.9.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.azure/azure-core -->
    <dependency>
      <groupId>com.azure</groupId>
      <artifactId>azure-core</artifactId>
      <version>1.3.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/io.projectreactor/reactor-core -->
    <dependency>
      <groupId>io.projectreactor</groupId>
      <artifactId>reactor-core</artifactId>
      <version>3.3.4.RELEASE</version>
    </dependency>

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

    <dependency>
      <groupId>com.microsoft.azure</groupId>
      <artifactId>azure</artifactId>
      <version>1.33.0</version>
    </dependency>

Can someone please point out if something is missing, Or if I have to change anything here?

2 Answers

Only the dependency of azure-storage-blob is needed for Azure Storage Blob SDK.

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-storage-blob</artifactId>
    <version>12.9.0</version>
</dependency>

And there is the sample about creating a container.

// From the Azure portal, get your Storage account's name and account key. 
String accountName = "";
String accountKey = "";

// Use your Storage account's name and key to create a credential object; this is used to access your account.
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);

// From the Azure portal, get your Storage account blob service URL endpoint.
// The URL typically looks like this:
String endpoint = String.format(Locale.ROOT, "https://%s.blob.core.windows.net", accountName);

// Create a BlobServiceClient object that wraps the service endpoint, credential and a request pipeline.
BlobServiceClient storageClient = new BlobServiceClientBuilder().endpoint(endpoint).credential(credential).buildClient();

// Create the container and return a container client object
BlobContainerClient containerClient = blobServiceClient.createBlobContainer(containerName);

Plz try to follow this quickstart to create the maven project.

I encountered same problem on clojure which also uses Azure's java library. In my case there was some other libraries that we were using which had jackson fasterxml dependency. azure-storage-blob also uses same dependency with a different version.

For us among those adding higher version of jason fasterxml dependency to dependencies solved our issue.

First you can find all the dependency tree, then analyzing the tree you can find most update version of jason fasterxml.

Below dependencies worked for us

                 [com.azure/azure-storage-blob "12.14.3"]
                 [com.fasterxml.jackson.core/jackson-databind "2.13.1"]
                 [com.fasterxml.jackson.core/jackson-core "2.13.1"]]

You can find more details here

Related