Can we use Cassandra in java without Maven? Can anyone provide sample code?

cassandra, datastax-java-driver

Solution

Check the DataStax Java Driver GitHub page, under the section "Getting the driver":

If you can't use a dependency management tool, a binary tarball is available for download.

Note that the link above is for the 3.2 version of the driver.

Untar the tarball, and put the following 3 JAR files into your classpath:

- cassandra-driver-core-3.2.0.jar

- cassandra-driver-mapping-3.2.0.jar

- cassandra-driver-extras-3.2.0.jar

Once that is done, you can follow the "Quick Start" section of the linked manual:

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;

Cluster cluster = null;
try {
    cluster = Cluster.builder()
            .addContactPoint("127.0.0.1")
            .build();
    Session session = cluster.connect();

    ResultSet rs = session.execute("select release_version from system.local");
    Row row = rs.one();
    System.out.println(row.getString("release_version"));
} finally {
    if (cluster != null) cluster.close();
}

Note that the above "quick start" code is exactly that, and assumes that:

- You are not using client-to-node SSL.

- You are not using user authentication.

- You are running Cassandra on your local machine, listening on 127.0.0.1

Problem

Can we use Cassandra without Maven in Java? If so, how can we do that? I've tried using it with JDBC DRIVER, but it is not helping the situation.

Original source