Getting Exception in thread "main" java.lang.NoClassDefFoundError: com/azure/core/util/ClientOptions

Getting Exception in thread "main" java.lang.NoClassDefFoundError: com/azure/core/util/ClientOptions

    I am working on test automating azure event hub functions using java in eclipse.
    
    I am trying to run the receiver application for EventHub functions.
    Below is the output:
    
        Exception in thread "main" java.lang.NoClassDefFoundError: com/azure/core/util/ClientOptions
            at com.azure.storage.blob.BlobContainerClientBuilder.<init>(BlobContainerClientBuilder.java:73)
            at AzureEventHubTest.Receiver.main(Receiver.java:44)
        Caused by: java.lang.ClassNotFoundException: com.azure.core.util.ClientOptions
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            ... 2 more
    
    
    **Here is the code:**
    
        package AzureEventHubTest;
        
        import com.azure.messaging.eventhubs.EventHubClientBuilder;
        import com.azure.messaging.eventhubs.EventProcessorClient;
        import com.azure.messaging.eventhubs.EventProcessorClientBuilder;
        import com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore;
        import com.azure.messaging.eventhubs.models.ErrorContext;
        import com.azure.messaging.eventhubs.models.EventContext;
        import com.azure.storage.blob.BlobContainerAsyncClient;
        import com.azure.storage.blob.BlobContainerClientBuilder;
        import com.azure.messaging.eventhubs.checkpointstore.blob.*;
        import java.util.function.Consumer;
        import java.util.concurrent.TimeUnit;
        import com.azure.core.util.*;
        import com.microsoft.azure.eventhubs.ConnectionStringBuilder;
        import com.microsoft.azure.eventhubs.EventData;
        import com.microsoft.azure.eventhubs.EventHubClient;
        import com.microsoft.azure.eventhubs.EventHubException;
        public class  Receiver {
            private static final String EH_NAMESPACE_CONNECTION_STRING = "//test";
                                                                        //sb://eqix-es-dev-eventhub.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=y3cVul6e5HRi4h30eFNwKBx3YLHaV+A7kQSX40TIeZc=";
            private static final String eventHubName = "//test";
            private static final String STORAGE_CONNECTION_STRING = "//test";
            private static final String STORAGE_CONTAINER_NAME = "//test";
            
            
            public static final java.util.function.Consumer<EventContext> PARTITION_PROCESSOR = eventContext -> {
                 System.out.printf("Processing event from partition %s with sequence number %d with body: %s %n", 
                         eventContext.getPartitionContext().getPartitionId(), eventContext.getEventData().getSequenceNumber(), eventContext.getEventData().getBodyAsString());
        
                    if (eventContext.getEventData().getSequenceNumber() % 10 == 0) {
                        eventContext.updateCheckpoint();
                    }
                };
        
                public static final java.util.function.Consumer<ErrorContext> ERROR_HANDLER = errorContext -> {
                    System.out.printf("Error occurred in partition processor for partition %s, %s.%n",
                        errorContext.getPartitionContext().getPartitionId(),
                        errorContext.getThrowable());
                };
        
                public static void main(String[] args) throws Exception {
                    BlobContainerAsyncClient blobContainerAsyncClient = new BlobContainerClientBuilder()
                        .connectionString(STORAGE_CONNECTION_STRING)
                        .containerName(STORAGE_CONTAINER_NAME)
                        .buildAsyncClient();
        
                    EventProcessorClientBuilder eventProcessorClientBuilder = new EventProcessorClientBuilder()
                        .connectionString(EH_NAMESPACE_CONNECTION_STRING, eventHubName)
                        .consumerGroup(EventHubClientBuilder.DEFAULT_CONSUMER_GROUP_NAME).processEvent(PARTITION_PROCESSOR)
                        .processError(ERROR_HANDLER)
                        .checkpointStore(new BlobCheckpointStore(blobContainerAsyncClient));
        
                    EventProcessorClient eventProcessorClient = eventProcessorClientBuilder.buildEventProcessorClient();
        
                    System.out.println("Starting event processor");
                    eventProcessorClient.start();
        
                    System.out.println("Press enter to stop.");
                    System.in.read();
        
                    System.out.println("Stopping event processor");
                    eventProcessorClient.stop();
                    System.out.println("Event processor stopped.");
        
                    System.out.println("Exiting process");
                }
        }
    
     
    Can anyone please help me to know where am I going wrong?
    What is wrong with my code or if anything else?
    I am stuck due to this.
    
 

这些是添加的maven依赖: 包括- azureeventhubs 依赖项和其他: com.azure azure-messaging-eventhubs-checkpointstore-blob 1.1.1 com.azure 天蓝色消息事件中心 5.1.1 org.slf4j slf4j-api 2.0.0-alpha1 org.slf4j slf4j-简单 2.0.0-alpha1 测试 com.azure 天蓝色存储 blob 12.10.0 org.testng 测试 7.3.0 测试 com.microsoft.azure 天蓝色事件中心 2.2.0

NoClassDefFoundError 当 class 不在您的 class 路径上时抛出。您是否尝试过此处命名的解决方案? exception in thread 'main' java.lang.NoClassDefFoundError:

ClientOptionsazure-core 版本 1.9.0 中引入,在 azure-storage-blob 版本 12.10.0.

中使用

1.1.1 版本的 azure-messaging-eventhubs-checkpointstore-blob 使用旧版本的 azure-core (1.5.1),它没有 ClientOptions。因此,在运行时,旧版本的 azure-core 正在加载,导致 NoClassDefFoundError 在创建 BlobContainer 时尝试使用 ClientOptions class.

因此,如果您将 azure-messaging-eventhubs-checkpointstore=blob 升级到 1.5.0 并将 azure-messaging-eventhubs 升级到 5.5.0,此问题将得到解决。

附带说明一下,您可以从依赖项列表中删除 azure-storage-blob,因为 azure-messaging-eventhubs-checkpointstore-blob 可传递地包含 azure-storage-blob.