NoClassDefFoundError - datastax java driver for Cassandra

限于喜欢 提交于 2020-01-02 23:14:33

问题


I am currently unable to connect to my cassandra database using the datastax driver. I am getting the following error:

com.datastax.driver.core.TransportException: [/127.0.0.1] Unexpected exception triggered (java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableSet;)
    at com.datastax.driver.core.Connection$Dispatcher.exceptionCaught(Connection.java:556)
    at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:122)

Caused by: java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableSet;
    at com.datastax.driver.core.DataType.<clinit>(DataType.java:144)
    at com.datastax.driver.core.Codec.<clinit>(Codec.java:31)

However, I have included the guava artefact in my pom.xml as follows:

<!-- Datastax driver -->

    <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-core</artifactId>
        <version>1.0.4</version>
    </dependency>

    <!-- Cassandra -->
    <dependency>
        <groupId>org.apache.cassandra</groupId>
        <artifactId>cassandra-all</artifactId>
        <version>1.2.9</version>
    </dependency>

    <!-- guava --<
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>15.0</version>
    </dependency>

Full pom.xml: http://pastebin.ubuntu.com/6358603/

Am I missing a dependency?


回答1:


According to its POM, version 1.0.4 of cassandra-driver-core uses version 14.0.1 of Guava, not version 15.0. I'm guessing you are seeing a version clash. Even if that version difference is not the cause of this problem, it might cause other problems.

You do not usually need to include transitive dependencies in POMs, Maven takes care of them for you. Or does your own code use Guava itself?




回答2:


Based on the advice of this question: no such method error: ImmutableList.copyOf()

I had to exclude the google collections jar:

    <dependency>
        <groupId>org.zkoss.zk</groupId>
        <artifactId>zkspring-core</artifactId>
        <version>3.1</version>
        <exclusions>
            <exclusion>
                <groupId>com.google.collections</groupId>
                <artifactId>google-collections</artifactId>
            </exclusion>
        </exclusions>
    </dependency>


来源:https://stackoverflow.com/questions/19768169/noclassdeffounderror-datastax-java-driver-for-cassandra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!