1

I am trying to connect DSE 5.0 server on ubuntu (with graph enable) with my java code but got this error

Exception in thread "main" java.lang.NoClassDefFoundError: io/netty/handler/timeout/IdleStateHandler
    at com.datastax.driver.core.Connection$Initializer.<init>(Connection.java:1409)
    at com.datastax.driver.core.Connection.initAsync(Connection.java:144)
    at com.datastax.driver.core.Connection$Factory.open(Connection.java:796)
    at com.datastax.driver.core.ControlConnection.tryConnect(ControlConnection.java:253)
    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:201)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:79)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1473)
    at com.datastax.driver.core.Cluster.init(Cluster.java:159)
    at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:330)
    at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:305)
    at com.datastax.driver.core.Cluster.connect(Cluster.java:247)
    at com.datastax.driver.core.DelegatingCluster.connect(DelegatingCluster.java:71)
    at com.datastax.driver.dse.DseCluster.connect(DseCluster.java:351)

As the error says the netty library is probably missing.

I added netty-all in my pom.xml but then also got same error.

Pom.xml

<dependency>
    <groupId>com.datastax.cassandra</groupId>
    <artifactId>dse-driver</artifactId>
    <version>1.1.1-beta1</version>
</dependency>
<dependency>
    <groupId>com.datastax.cassandra</groupId>
    <artifactId>dse-driver</artifactId>
    <version>1.1.1-beta1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>4.1.6.Final</version>
</dependency>

Thanks for help..!

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
Prakash P
  • 3,582
  • 4
  • 38
  • 66

1 Answers1

1

The java driver is built and tested against Netty 4.0 (see JAVA-1241 for 4.1 support). It's possible that there is some incompatibility that prevents this from working (although I see IdleStateHandler in that path in Netty 4.1).

If you need to use a different version of Netty in your project, you can consider using the shaded classifier of the driver which includes its own bundled version of netty under its own package structure. Since you are using the dse driver you'll also need to exclude the core driver from its dependency definition (this will be less complicated in the future):

    <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-core</artifactId>
        <version>3.1.3</version>
        <classifier>shaded</classifier>
        <!-- Because the shaded JAR uses the original POM, you still need
             to exclude this dependency explicitly: -->
        <exclusions>
            <exclusion>
                <groupId>io.netty</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>dse-driver</artifactId>
        <version>1.1.1-beta1</version>
        <exclusions>
            <exclusion>
                <groupId>com.datastax.cassandra</groupId>
                <artifactId>cassandra-driver-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
Andy Tolbert
  • 11,418
  • 1
  • 30
  • 45
  • isn't `dse-driver` contain netty driver by default, then what can be the possible cause of `.NoClassDefFoundError: io/netty/handler/timeout/IdleStateHandler` – Prakash P Jan 10 '17 at 05:53
  • If you could also this : -> If I want to use dse-graph feature, which libraries I wil have to include `java-dse-graph` + `dse-driver` + `cassandra-driver-core` or only `java-dse-graph` – Prakash P Jan 10 '17 at 06:04
  • By excluding the core driver dependency from the dse-driver, it should not pull in netty as well since that is where the netty dependency comes from. w/r/t java-dse-graph, you can add that dependency, and then call out the dse-driver dependency directly like in my answer. It's not pretty but it'll work. – Andy Tolbert Jan 10 '17 at 17:34