NoClassDefFoundError:kafka / api / OffsetRequest

时间:2016-01-06 06:53:42

标签: java maven apache-kafka apache-storm trident

我正在尝试使用apache storm,kafka和trident编写实时处理应用程序 但在TridentKafkaConfig的初始化中,我看到了这个错误

Exception in thread "main" java.lang.NoClassDefFoundError: kafka/api/OffsetRequest
at storm.kafka.KafkaConfig.<init>(KafkaConfig.java:43)
at storm.kafka.trident.TridentKafkaConfig.<init>(TridentKafkaConfig.java:30)
at spout.TestSpout.<clinit>(TestSpout.java:22)
at IOTTridentTopology.initializeTridentTopology(IOTTridentTopology.java:31)
at IOTTridentTopology.main(IOTTridentTopology.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: kafka.api.OffsetRequest
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 10 more

我的鲸鱼喷水课程是

public class TestSpout extends OpaqueTridentKafkaSpout {

private static TridentKafkaConfig config;
private static BrokerHosts HOSTS = new ZkHosts(TridentConfig.ZKHOSTS);
private static String TOPIC = "test";
private static int BUFFER_SIZE = TridentConfig.BUFFER_SIZE;

static{
    config = new TridentKafkaConfig(HOSTS, TOPIC);
    config.scheme = new SchemeAsMultiScheme(new RawScheme());
    config.bufferSizeBytes = BUFFER_SIZE;
}

public TestSpout(TridentKafkaConfig config) {
    super(config);
}

public TestSpout() {
    super(config);
}
}

主要课程:

 public static void main(String[] args) {
    initializeTridentTopology();
}

private static void initializeTridentTopology() {
    TridentTopology topology = new TridentTopology();
    TestSpout spout = new TestSpout();
    //////////////// test  //////////////////////

    topology.newStream("testspout", spout).each(spout.getOutputFields(), new TestFunction(), new Fields());

    ///////////////  end test ///////////////////

    LocalCluster cluster = new LocalCluster();

    Config config = new Config();
    config.setDebug(false);
    config.setMaxTaskParallelism(1);
    config.registerSerialization(storm.kafka.trident.GlobalPartitionInformation.class);
    config.registerSerialization(java.util.TreeMap.class);
    config.setNumWorkers(5);

    config.setFallBackOnJavaSerialization(true);

    cluster.submitTopology("KafkaTrident", config, topology.build());

}

和我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd">     4.0.0

<groupId>IOT</groupId>
<artifactId>ver0.1</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>


    <dependency>
        <groupId>org.apache.storm</groupId>
        <artifactId>storm-core</artifactId>
        <version>0.9.3</version>
    </dependency>


    <dependency>
        <groupId>org.apache.storm</groupId>
        <artifactId>storm-kafka</artifactId>
        <version>0.9.3</version>
    </dependency>



</dependencies>

我正在尝试不同版本的storm-kafka(0.9.3和0.9.4和0.9.5以及0.9.6和0.10.0)和storm-core(9.3和9.4和9.6)

但我仍然看到我之前的错误

通过谷歌搜索我找到了这个链接但是......

ClassNotFoundException: kafka.api.OffsetRequest

2 个答案:

答案 0 :(得分:4)

经过一些谷歌搜索后,我找到了这个链接 https://github.com/wurstmeister/storm-kafka-0.8-plus-test 并在pom.xml文件中找到了我的答案

通过添加此代码并找到兼容版本的kafka所有问题已解决

 <dependency>
        <groupId>org.apache.kafka</groupId>
        <artifactId>kafka_2.11</artifactId>
        <version>0.9.0.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
            <exclusion>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

答案 1 :(得分:2)

如果使用LocalCluster部署风暴拓扑,则需要将Kafka lib添加到依赖项(对于Storm 0.10.0):

    <dependency>
       <groupId>org.apache.kafka</groupId>
       <artifactId>kafka_2.9.2</artifactId>
       <version>0.8.1.1</version>
     </dependency>
由于 org.apache.kafka 提供对storm-kafka的依赖,因此错过了

kafka.api.OffsetRequest 类: http://mvnrepository.com/artifact/org.apache.storm/storm-kafka/0.10.0。有关详细信息,请参阅提供的依赖项部分。