astyanax cassandra: The type org.apache.cassandra.thrift.Cassandra$Client cannot be resolved. It is indirectly referenced from required .class files

StackOverflow https://stackoverflow.com/questions/17823586

  •  04-06-2022
  •  | 
  •  

Question

My internship needs me get familiar with cassandra. I downloaded astyanax cassandra from: https://github.com/Netflix/astyanax

After building astyanax from source via the commands: git clone git@github.com:Netflix/astyanax.git cd astyanax ./gradlew build

I created a new java project and copy+paste the sample code from here: https://github.com/Netflix/astyanax/blob/master/astyanax-examples/src/main/java/com/netflix/astyanax/examples/AstCQLClient.java

Now the problems arose. I did fix the path configuration, which is importing all .jar files generated from the gradlew build. But one (long)line of code is highlighted by red dash:

context = new AstyanaxContext.Builder()
.forCluster("Test Cluster")
.forKeyspace("test1")
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()      
    .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
    .setPort(9160)
    .setMaxConnsPerHost(1)
    .setSeeds("127.0.0.1:9160")
)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()      
    .setCqlVersion("3.0.0")
    .setTargetCassandraVersion("1.2"))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());

The warning message is: The type org.apache.cassandra.thrift.Cassandra$Client cannot be resolved. It is indirectly referenced from required .class files

I need experts help. Thanks a lot!!!

Was it helpful?

Solution

Sounds like you are missing the thrift dependency (thrift jar file). Either that or you are using an incompatible version of thrift. The simple solution is to use Maven and add the Astyanax dependency to your project. The more complex solution is to verify that that version of thrift you are import is compatible with the version of Astyanax being used.

Maven dependency (add this to your pom file):

<dependency>
    <groupId>com.netflix.astyanax</groupId>
    <artifactId>astyanax</artifactId>
    <version>1.56.42</version>
</dependency>

You can work out a compatible version of Thrift for your Astyanax client using Astyanax's wiki. But knowing you built the project from Github, you want the latest thrift that is compatible with Cassandra, so you are after Thrift 9.0+ (for example libthrift-0.9.0.jar).

OTHER TIPS

I think first of all you should properly install Cassandra Server on your local. You can find the latest source from Cassandra Repo.

Then you can follow this link configure Cassandra Server. Though i don't think you have to change anything in the configuration files as cassandra source is properly configured for running in local mode.

Then create a Maven Project from IDE, add the dependency shown by @Lyuben Todorov i.e

<dependency>
    <groupId>com.netflix.astyanax</groupId>
    <artifactId>astyanax</artifactId>
    <version>1.56.42</version>
</dependency>

Then try some test example from the Astyanax wiki

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top