0

I'm trying to implement a piece of code in Java using Azure Java SDK that allows me to upload a file (jpg, in mycase) to a Azure container. I have written this, but it fails:

String ENDPOINT= "https://myaccount.blob.core.windows.net";

BlobContainerClient blobContainerClient = new BlobContainerClientBuilder().
    endpoint(ENDPOINT).
    credential(CREDENTIAL).
    containerName(CONTAINER_NAME).
    buildClient();

// Get a reference to a local image
BlobClient blobClient = blobContainerClient.getBlobClient(myJpgLocalPath + myJpgFile);

// Set headers
blobClient.setHttpHeaders(new BlobHttpHeaders().setContentType("image/jpeg"));

// Upload the blob
blobClient.uploadFromFile(myJpgLocalPath + myJpgFile, false);

Another approach I've done is this:

BlobServiceClient storageClient = new BlobServiceClientBuilder().
    endpoint(ENDPOINT).
    credential(CREDENTIAL).
    buildClient();

BlobContainerClient blobContainerClient = storageClient.getBlobContainerClient(CONTAINER_NAME); 

// Get a reference to a local image
BlobClient blobClient = blobContainerClient.getBlobClient(myJpgLocalPath + myJpgFile);
    
// Set headers
blobClient.setHttpHeaders(new BlobHttpHeaders().setContentType("image/jpeg"));
    
// Upload the blob
blobClient.uploadFromFile(myJpgLocalPath + myJpgFile, false);

None of these two works at all and fails even building the client.

The errors shown are these two:

java.lang.ClassNotFoundException: com.fasterxml.jackson.dataformat.xml.PackageVersion
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1412)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1220)
        at com.azure.core.implementation.jackson.JacksonVersion.<init>(JacksonVersion.java:46)
        at com.azure.core.implementation.jackson.JacksonVersion.getInstance(JacksonVersion.java:72)
        at com.azure.core.implementation.jackson.ObjectMapperShim.<clinit>(ObjectMapperShim.java:40)
        at com.azure.core.util.serializer.JacksonAdapter.<init>(JacksonAdapter.java:81)
        at com.azure.core.util.serializer.JacksonAdapter.<init>(JacksonAdapter.java:59)
        at com.azure.core.util.serializer.JacksonAdapter$SerializerAdapterHolder.<clinit>(JacksonAdapter.java:114)
        at com.azure.core.util.serializer.JacksonAdapter.createDefaultSerializerAdapter(JacksonAdapter.java:123)
        at com.azure.storage.blob.implementation.util.ModelHelper.<clinit>(ModelHelper.java:62)
        at com.azure.storage.blob.BlobUrlParts.parse(BlobUrlParts.java:371)
        at com.azure.storage.blob.BlobContainerClientBuilder.endpoint(BlobContainerClientBuilder.java:181)
...

java.lang.NoClassDefFoundError: Could not initialize class com.azure.storage.blob.implementation.util.ModelHelper
        at com.azure.storage.blob.BlobUrlParts.parse(BlobUrlParts.java:371)
        at com.azure.storage.blob.BlobContainerClientBuilder.endpoint(BlobContainerClientBuilder.java:181)
...

What I am doing bad?

Thanks!

4
  • What's the error you are getting? Commented Sep 12, 2022 at 10:35
  • post edited with the errors Commented Sep 12, 2022 at 12:18
  • Can you share the value of your ENDPOINTvariable? Replace the account name with something else if you like to. Commented Sep 12, 2022 at 12:23
  • Sure. I wrote it on the top of the code Commented Sep 12, 2022 at 12:26

1 Answer 1

0

The Azure Storage Blob SDK is attempting to determine the version of Jackson Dataformat XML and it's unable to find the PackageVersion class in jackson-dataformat-xml. This is indicating a few possible issues, Jackson Dataformat XML isn't part of the application or the Azure Storage Blob SDK doesn't have access to PackageVersion.

Aside from that the code you've written for uploading the blob should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.