Building and IDE Integration

Building From Source

Building Cassandra from source is the first important step in contributing to the Apache Cassandra project. You’ll need to install Java 8, Git, and Ant first.

The source code for Cassandra is shared on the central Apache Git repository and organized by branch, one branch for each major version. You can access the code for the current development branch using:

git clone https://gitbox.apache.org/repos/asf/cassandra.git cassandra-trunk

Other branches will point to different versions of Cassandra. Switching to a different branch requires checking out the branch. For example, to checkout the latest version of Cassandra 3.0, use:

git checkout cassandra-3.0

You can get a list of available branches with git branch.

Build Cassandra using ant:

ant

This may take a significant amount of time depending on artifacts that have to be downloaded or the number of classes that need to be compiled.

Hint

You can setup multiple working trees for different Cassandra versions from the same repository using git-worktree.

Now you can get started with Cassandra using IntelliJ IDEA or Eclipse.

Setting up Cassandra in IntelliJ IDEA

IntelliJ IDEA by JetBrains is one of the most popular IDEs for Cassandra and Java development in general. The Community Edition can be freely downloaded with all features needed to get started developing Cassandra.

Use the following procedure for Cassandra 2.1.5+. If you wish to work with older Cassandra versions, see our wiki for instructions.

First, clone and build Cassandra. Then execute the following steps to use IntelliJ IDEA.

  1. Generate the IDEA files using ant:

ant generate-idea-files
  1. Start IDEA.

  2. Open the IDEA project from the checked-out Cassandra directory using File > Open in IDEA’s menu.

The project generated by ant generate-idea-files contains nearly everything you need to debug Cassandra and execute unit tests. You should be able to:

  • Run/debug defaults for JUnit

  • Run/debug configuration for Cassandra daemon

  • Read/modify the license header for Java source files

  • Study Cassandra code style

  • Inspections

Opening Cassandra in Apache NetBeans

Apache NetBeans is an older open source Java IDE, and can be used for Cassandra development. There is no project setup or generation required to open Cassandra in NetBeans. Use the following procedure for Cassandra 4.0+.

First, clone and build Cassandra. Then execute the following steps to use NetBeans.

  1. Start Apache NetBeans

  2. Open the NetBeans project from the ide/ folder of the checked-out Cassandra directory using File > Open Project in NetBeans' menu.

You should be able to:

  • Build code

  • Run code

  • Debug code

  • Profile code

These capabilities use the build.xml script. Build/Run/Debug Project are available via the Run/Debug menus, or the project context menu. Profile Project is available via the Profile menu. In the opened Profiler tab, click the green "Profile" button. Cassandra’s code style is honored in ide/nbproject/project.properties. The JAVA8_HOME system environment variable must be set for NetBeans to execute the Run/Debug/Profile ant targets to execute.

Setting up Cassandra in Eclipse

Eclipse is a popular open source IDE that can be used for Cassandra development. Various Eclipse environments are available from the download page. The following guide was created with "Eclipse IDE for Java Developers".

These instructions were tested on Ubuntu 16.04 with Eclipse Neon (4.6) using Cassandra versions 2.1 through 3.x.

First, clone and build Cassandra. Then execute the following steps to use Eclipse.

  1. Generate the IDEA files using ant:

ant generate-eclipse-files
  1. Start Eclipse.

  2. Open the Eclipse project from the checked-out Cassandra directory using File > Import > Existing Projects and Workspace > Select git directory. Select the correct branch, such as cassandra-trunk.

  3. Confirm and select Finish to import your project.

Find the project in Package Explorer or Project Explorer. You should not get errors if you build the project automatically using these instructions. Don’t set up the project before generating the files with ant.

You should be able to:

  • Run/debug defaults for JUnit

  • Run/debug Cassandra

  • Study Cassandra code style

Unit tests can be run from Eclipse by simply right-clicking the class file or method and selecting Run As > JUnit Test. Tests can be debugged by defining breakpoints (double-click line number) and selecting Debug As > JUnit Test.

Alternatively all unit tests can be run from the command line as described in testing.

Debugging Cassandra Using Eclipse

There are two ways to start a local Cassandra instance with Eclipse for debugging. You can either start Cassandra from the command line or from within Eclipse.

Debugging Cassandra started at command line
  1. Set environment variable to define remote debugging options for the JVM: export JVM_EXTRA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1414"

  2. Start Cassandra by executing the ./bin/cassandra

Next, connect to the running Cassandra process by:

  1. In Eclipse, select Run > Debug Configurations.

image
  1. Create new remote application.

image
  1. Configure connection settings by specifying a name and port 1414. Confirm Debug and start debugging.

image
Debugging Cassandra started from Eclipse

Cassandra can also be started directly from Eclipse if you don’t want to use the command line.

  1. In Eclipse, select Run > Run Configurations.

image
  1. Create new application.

image
  1. Specify name, project and main class org.apache.cassandra.service.CassandraDaemon

image
  1. Configure additional JVM specific parameters that will start Cassandra with some of the settings created by the regular startup script. Change heap related values as needed.

-Xms1024M -Xmx1024M -Xmn220M -Xss256k -ea -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCondCardMark -javaagent:./lib/jamm-0.3.0.jar -Djava.net.preferIPv4Stack=true
image
  1. Confirm Debug and you should see the output of Cassandra start up in the Eclipse console.

You can now set breakpoints and start debugging!