- 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:git clone https://github.com/<your_git_name>/cassandra.git cassandra
Building Cassandra
build.xmllocated in the root of the project content, has various tasks defined (you can list all of them with some short descriptions by runningant -p).-Duse.jdk11=trueto your Ant build command or export the environment variableCASSANDRA_USE_JDK11=true. Otherwise, if you run the build using Java 11, the build script complains.antorant 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 thebin/cassandrascript.Building a distribution
Some tasks you might be interested in are: build- compile the production code without producing any JARsbuild-test- compile the test code without producing any JARsartifacts- generate Cassandra distribution inbuild/distdirectory and package it totar.gz(with and without sources)mvn-install- generatecassandra-allJAR artifact along with sources and JavaDoc, and install it in the local Maven repositoryrealclean- clean the project from any build products, as well as from any dependencies (in fact that means removingbuildandlibdirectories) 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.ant generate-idea-files
- Start IDEA.
File > Openin IDEA’s menu.ant generate-idea-filescontains 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.
- Start Apache NetBeans
- ide/ folder of the checked-out Cassandra directory using
File > Open Projectin 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_HOMEsystem environment variable must be set for NetBeans to execute the Run/Debug/Profileanttargets 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.ant generate-eclipse-files
- Start Eclipse.
File > Import > Existing ProjectsandWorkspace > Selectgit directory. Select the correct branch, such ascassandra-trunk.Finishto import your project.Package ExplorerorProject 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 withant. 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 selectingDebug 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
export JVM_EXTRA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1414"./bin/cassandraNext, connect to the running Cassandra process by:Run > Debug Configurations.
1.

- connection settings by specifying a name and port 1414. Confirm
Debugand start debugging.
Debugging Cassandra started from Eclipse
Cassandra can also be started directly from Eclipse if you don’t want to use the command line. Run > Run Configurations.
1.

org.apache.cassandra.service.CassandraDaemon
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

Debugand you should see the output of Cassandra start up in the Eclipse console. You can now set breakpoints and start debugging!General notes
antcommands above. If you do, startantwith therealcleanoption:
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.ant realclean
