我和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
你知道问题出在哪里吗?
2条答案
按热度按时间5gfr0r5j1#
org.apache.kafka.clients.producer.Producer
是在kafka-clients
神器。你应该使用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文件或者你可以简单地把所有的东西打包在一起,使用
将此添加到pom.xml: