kafka生产者异常noclassdeffounderror

zdwk9cvp  于 2021-06-08  发布在  Kafka
关注(0)|答案(2)|浏览(578)

我和Kafka制作人有些问题,但我不知道怎么解决
我的maven依赖:

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka_2.10</artifactId>
    <version>0.10.1.1</version>
</dependency>

如果我创建:

Producer<String, byte[]> producer = createKafkaProducer();

我成为例外:

java.lang.NoClassDefFoundError: org/apache/kafka/clients/producer/Producer
at de.dienes.opitz.node.NodesValue.onSubscriptionValue(NodesValue.java:120)
at org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaMonitoredItem.onValueArrived(OpcUaMonitoredItem.java:176)
at org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaSubscriptionManager.lambda$null$28(OpcUaSubscriptionManager.java:547)
at org.eclipse.milo.opcua.stack.core.util.ExecutionQueue$PollAndExecute.run(ExecutionQueue.java:107)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.clients.producer.Producer
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 9 common frames omitted

你知道问题出在哪里吗?

5gfr0r5j

5gfr0r5j1#

org.apache.kafka.clients.producer.Producer 是在 kafka-clients 神器。你应该使用

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>0.10.2.1</version>
</dependency>
``` `kafka_2.10` 是代理的工件。如果您只是编写一个生产者/消费者(除了针对测试集群对生产者/消费者进行集成测试),则不需要它。
b09cbbtk

b09cbbtk2#

这也发生在我身上。我用bootstrapextansionschema解决了这个问题:
java-xbootclasspath/a:tyrus.jar-jar myjar.jar
您可以添加多个按分隔的库 : java-xbootclasspath/a:/usr/local/kafka/libs/kafka-clien-1.0.0。jar:tyrus.jar -jar myjar.jar文件
或者你可以简单地把所有的东西打包在一起,使用

maven-assembly-plugin

将此添加到pom.xml:

<plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                 <executions>
                     <execution>
                         <phase>package</phase>
                         <goals>
                             <goal>single</goal>
                         </goals>
                     </execution>
                 </executions>
                 <configuration>
                     <descriptorRefs>
                         <descriptorRef>jar-with-dependencies</descriptorRef>
                     </descriptorRefs>
                    <archive>
                         <manifest>
                             <mainClass>pakageName.MainClassName</mainClass>
                         </manifest>
                     </archive>
                 </configuration>
             </plugin>

相关问题