• Building and IDE Integration
  • Prerequisites
  • Getting the source code
  • Building Cassandra
  • Building a distribution
  • Setting up Cassandra in IntelliJ IDEA
  • Opening Cassandra in Apache NetBeans
  • Setting up Cassandra in Eclipse
  • Debugging Cassandra Using Eclipse
  • Debugging Cassandra started at command line
  • Debugging Cassandra started from Eclipse
  • General notes

    Building and IDE Integration

    Prerequisites

    Building Cassandra from source is the first important step in contributing to the Apache Cassandra project. You will need to install Java (JDK 8 or 11, depending on which version you want to build Cassandra against, best is to install both and then switch between them when needed), Git, and Ant (including ant-optional).

    Getting the source code

    gitbox.apache.org/repos/asf/cassandra.git (the primary location) or at github.com/apache/cassandra (a mirror location). However, to develop a patch or a new feature, you should fork the Cassandra project first and then clone it from your own fork:
    1. git clone https://github.com/<your_git_name>/cassandra.git cassandra

    Building Cassandra

    build.xml located in the root of the project content, has various tasks defined (you can list all of them with some short descriptions by running ant -p). -Duse.jdk11=true to your Ant build command or export the environment variable CASSANDRA_USE_JDK11=true. Otherwise, if you run the build using Java 11, the build script complains. ant or ant jar. 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. When the build completes, you can find a JAR file in the build directory, and the database service can be started with the bin/cassandra script.

    Building a distribution

    Some tasks you might be interested in are:
  • build - compile the production code without producing any JARs
  • build-test - compile the test code without producing any JARs
  • artifacts - generate Cassandra distribution in build/dist directory and package it to tar.gz (with and without sources)
  • mvn-install - generate cassandra-all JAR artifact along with sources and JavaDoc, and install it in the local Maven repository
  • realclean - clean the project from any build products, as well as from any dependencies (in fact that means removing build and lib directories) Testing section.

    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+: 1.
    1. ant generate-idea-files
  1. Start IDEA.
  2. File > Open in IDEA’s menu. 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 the elder of the open sourced java IDEs, 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. 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 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

    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.
    1. ant generate-eclipse-files
  1. Start Eclipse.
  2. File > Import > Existing Projects and Workspace > Select git directory. Select the correct branch, such as cassandra-trunk.
  3. Finish to import your project. 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 Run As > JUnit Test. Tests can be debugged by defining breakpoints (double-click line number) and selecting Debug As > JUnit Test. 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. export JVM_EXTRA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1414"
  2. ./bin/cassandra Next, connect to the running Cassandra process by:
  3. Run > Debug Configurations. image 1. image
  4. 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.
  5. Run > Run Configurations. image 1. image
  6. org.apache.cassandra.service.CassandraDaemon image 1.
    1. -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
  7. Debug and you should see the output of Cassandra start up in the Eclipse console. You can now set breakpoints and start debugging!

    General notes

    ant commands above. If you do, start ant with the realclean option:
    1. ant realclean
    Remember that all the tasks mentioned above may depend on building source files. If there are actual compilation errors in the code, you may not be able to generate project files for IntelliJ Idea, Netbeans, or Eclipse. It is especially important that you have imported the project adequately into IDE before doing merges or rebases. Otherwise, if there are conflicts, the project cannot be opened in IDE, and you will be unable to use any fancy conflict resolution tools offered by those IDEs.