Reputation: 1379
I'm trying to connect to cassandra from java using the now recommended datastax java driver 3.0 but I get the exception
Caused by: java.lang.IllegalStateException: Detected Guava issue #1635 which indicates that a version of Guava less than 16.01 is in use. This introduces codec resolution issues and potentially other incompatibility issues in the driver. Please upgrade to Guava 16.01 or later.
at com.datastax.driver.core.SanityChecks.checkGuava(SanityChecks.java:62)
at com.datastax.driver.core.SanityChecks.check(SanityChecks.java:36)
at com.datastax.driver.core.Cluster.<clinit>(Cluster.java:67)
I have downloaded the zip file and compiled with maven mvn clean package -Dskiptests
Inside the target folder for the core driver I found a jar named java-driver-3.0/cassandra-driver-core-3.0.1-SNAPSHOT-shaded.jar
which I added to my projects libraries.
Trying to run the project gives the above exception.
Trying to connect to cluster as below
private static Cluster CLUSTER;
private static Session SESSION;
public static Cluster createCluster() {
CLUSTER = Cluster.builder().addContactPoint("127.0.0.1").build();
SESSION = CLUSTER.connect();
ResultSet rs = SESSION.execute("select release_version from system.local");
Row row = rs.one();
System.out.println(row.getString("relese_version"));
return CLUSTER;
}
public static Cluster getCluster() {
if (null == CLUSTER) {
CLUSTER = createCluster();
}
return CLUSTER;
}
I suspect the solution is here but I don't know what I am supposed to do with that XML. I am relatively a greenhorn in Maven please go easy on me. Finally, does Hector client have support for Cassandra 3.x cause if I can't resolve the above issue I wouldn't mind using hector.
Upvotes: 1
Views: 920
Reputation: 1379
I finally found the solution was before me in plain sight. as explained on this page. pardon the raw link I am on mobile browser with no js support but I will edit this answer appropriately when I am on my desktop browser.
https://java.net/jira/browse/GLASSFISH-20850
glassfish 4 includes guava 14.0 jar which is apparently favoured during compilation over the the guava 16.01 or above recommended for the driver. under WEB-INF directory in the files tab of your project, locate sun-web.XML and change the entry
to restart the server and the error should disappear.
Upvotes: 0
Reputation: 11638
The shaded configuration of the java driver only shades netty libraries, not guava. The main motivation for not shading guava is that the java driver's public API exposes guava classes like ListenableFuture
and TypeToken
in a number of places.
How are you running your code? Are you using maven exec:java
or some kind of IDE?
My guess is somewhere in your classpath exists a guava library older than 16.01. One way of validating which jar may be used is to take a class from it and print it's source location. i.e. you could try this for ListenableFuture
which is part of the guava library:
System.out.println(ListenableFuture.class.getProtectionDomain().getCodeSource().getLocation().getPath());
This will print the location of the jar containing that class, i.e.:
/Users/username/.m2/repository/com/google/guava/guava/16.0.1/guava-16.0.1.jar
Finally, does Hector client have support for Cassandra 3.x cause if I can't resolve the above issue I wouldn't mind using hector.
Hector is a client over the thrift transport which has since been deprecated and will be removed in Cassandra 4.0. It is no longer an active project so I would not recommend using it.
Upvotes: 1