KafkaSpout throws NoClassDefFoundError for log4j

前端 未结 3 757
礼貌的吻别
礼貌的吻别 2021-01-19 01:06

For some reason I get the following error when I try to run my topology on a Storm cluster:

java.lang.NoClassDefFoundError: Could not initialize class org.ap         


        
相关标签:
3条回答
  • 2021-01-19 01:54

    I have occured to the same problem when I included kafka like you, so I included kafka by another way according to the throw exception:

    SLF4J: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError. SLF4J: See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.

    You can include kafka in the following way:

    <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka_2.10</artifactId>
            <version>${kafka.version}</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>
    
    0 讨论(0)
  • 2021-01-19 01:55

    Do you use the "right" logging framework?

    From https://storm.apache.org/2013/12/08/storm090-released.html

    Logging Changes

    Another important change in 0.9.0 has to do with logging. Storm has largely switched over to the slf4j API (backed by a logback logger implementation). Some Storm dependencies rely on the log4j API, so Storm currently depends on log4j-over-slf4j.

    These changes have implications for existing topologies and topology components that use the log4j API.

    In general, and when possible, Storm topologies and topology components should use the slf4j API for logging.

    If you do not use the same logging framework as Storm, you need to include the used libraries into your jar file together with your topology code.

    0 讨论(0)
  • 2021-01-19 02:04

    The thing is that you should include Kafka in the following way:

       <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka_2.10</artifactId>
            <version>0.8.1.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.zookeeper</groupId>
                    <artifactId>zookeeper</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    

    For the following reason:

    Note that the ZooKeeper and log4j dependencies are excluded to prevent version conflicts with Storm's dependencies.

    0 讨论(0)
提交回复
热议问题