Differences between revisions 27 and 28
Revision 27 as of 2014-08-07 19:09:34
Size: 4512
Editor: RobertStupp
Comment: Note to link IDEA to .classpath
Revision 28 as of 2015-04-07 16:31:59
Size: 5780
Editor: RobertStupp
Comment: add generate-idea-files ant target
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

<<TableOfContents>>

= Setup Cassandra as a Project (C* 2.1 and newer) =

Since 2.1.5, there is a new ant target {{{generate-idea-files}}}

''' Prerequisites: ''' JDK7 (Cassandra 2.0+), Apache Ant (http://ant.apache.org/) and Git (http://git-scm.com/) are required to get Cassandra running in IDEA.

 1. Clone Cassandra from apache's Git repository. <<BR>><<BR>>
 for trunk branch (JDK7 required)
 {{{
 git clone git://git.apache.org/cassandra.git
 }}}
 for cassandra-2.1 branch
 {{{
 git clone –b cassandra-2.1 git://git.apache.org/cassandra.git
 }}}
 2. Once git has finished cloning the repository, generate the eclipse files using ant.
 {{{
 ant generate-idea-files
 }}}
 3. Start IDEA
 4. Just open the IDEA project from the checked out Cassandra directory using the menu item ''Open'' in IDEA's ''File'' menu

The project generated by the ant task {{{generate-idea-files}}} contains nearly everything you need to debug Cassandra and execute unit tests.

 * Run/debug defaults for JUnit
 * Run/debug configuration for Cassandra daemon
 * License header for Java source files
 * Cassandra code style
 * Inspections

= Setup Cassandra as a Project (C* 1.2, 2.0, <= 2.1.4) =

''' The following applies to Cassandra sources for versions 1.2.x, 2.0.x and up to 2.1.4 '''
Line 11: Line 47:

<<TableOfContents>>

= Setup Cassandra as a Project =
Line 50: Line 82:
= Building & Testing Cassandra via Ant = == Building & Testing Cassandra via Ant ==
Line 70: Line 102:
= Create a RUN configuration = == Create a RUN configuration ==
Line 92: Line 124:
= Verify Cassandra is running via IDEA = == Verify Cassandra is running via IDEA ==
Line 109: Line 141:
= Notes = == Notes ==
Line 111: Line 143:
== Java 7 since Cassandra 2.0 == === Java 7 since Cassandra 2.0 ===
Line 119: Line 151:
== Link IDEA to .classpath == === Link IDEA to .classpath ===

IDEA is now open source! The free community edition at http://www.jetbrains.org is all you need for Cassandra development. (You don't need J2EE or Web tools.)

Setup Cassandra as a Project (C* 2.1 and newer)

Since 2.1.5, there is a new ant target generate-idea-files

Prerequisites: JDK7 (Cassandra 2.0+), Apache Ant (http://ant.apache.org/) and Git (http://git-scm.com/) are required to get Cassandra running in IDEA.

  1. Clone Cassandra from apache's Git repository.

    for trunk branch (JDK7 required)

     git clone git://git.apache.org/cassandra.git
    for cassandra-2.1 branch
     git clone –b cassandra-2.1 git://git.apache.org/cassandra.git 
  2. Once git has finished cloning the repository, generate the eclipse files using ant.
     ant generate-idea-files
  3. Start IDEA
  4. Just open the IDEA project from the checked out Cassandra directory using the menu item Open in IDEA's File menu

The project generated by the ant task generate-idea-files contains nearly everything you need to debug Cassandra and execute unit tests.

  • Run/debug defaults for JUnit
  • Run/debug configuration for Cassandra daemon
  • License header for Java source files
  • Cassandra code style
  • Inspections

Setup Cassandra as a Project (C* 1.2, 2.0, <= 2.1.4)

The following applies to Cassandra sources for versions 1.2.x, 2.0.x and up to 2.1.4

To quickly import Cassandra into IntelliJ and start coding simply:

  1. Run "ant generate-eclipse-files"
  2. File -> Import Project

(The IntelliJ Eclipse plugin must be enabled.)

If you want IDEA to handle more of the environment for you, keep reading.

Prerequisites: JDK6 (Cassandra 1.2) or JDK7 (Cassandra 2.0+), Apache Ant (http://ant.apache.org/) and Git (http://git-scm.com/) are required to get Cassandra running in IDEA.

  1. Clone Cassandra from apache's Git repository.

    for trunk branch (JDK7 required)

     git clone git://git.apache.org/cassandra.git
    for cassandra-1.2 branch
     git clone –b cassandra-1.2 git://git.apache.org/cassandra.git 
  2. Once git has finished cloning the repository, generate the eclipse files using ant.
     ant generate-eclipse-files
  3. Start IDEA
  4. Click Import Project.

  5. Navigate to the newly cloned cassandra directory and click OK.

    1_Import Casandra.png

  6. Select Import project from external model, pick Eclipse then click OK.

    2_Import as Eclipse project.png

  7. Select Next - make sure that Link created IntelliJ IDEA modules to Eclipse project files is checked

    3b-import-project.png

  8. Select cassandra and click Finish. You now have a successfully imported Cassandra project.

    5_Import Completed.png

Building & Testing Cassandra via Ant

To build Cassandra we need to import ant's build file, aka build.xml.

  1. Select the Ant Build tab from IDEA (right hand side in the screen shot below).

  2. Select the + (Add).

  3. Navigate to Cassandra's root directory (based on the tutorial this would be ~/workspace/cassandra/) and select build.xml.

  4. Click OK. The different ant targets will now be available for execution.

    Adding Ant Config.png

    Building / Testing Cassandra via Ant
    Once the ant build file is added to IDEA you can compile cassandra via the build target. The unit tests are located under the test target.
    To run a target select it and then click idea_run.png.

    10_Successful Build.png

Create a RUN configuration

  1. Select Run > Edit Configurations... and click the + (Add New Configuration).

  2. Populate the config with the following:

     Main class: org.apache.cassandra.service.CassandraDaemon
     VM options:
       -Dcassandra-foreground=yes
       -Dcassandra.config=file://$PROJECT_DIR$/conf/cassandra.yaml
       -Dcassandra.storagedir=$PROJECT_DIR$/data
       -Dlogback.configurationFile=file://$PROJECT_DIR$/conf/logback.xml
       -Dcassandra.logdir=$PROJECT_DIR$/data/logs
       -ea
       -Xmx1G
  3. Click OK.

    Run Configuration.png

Verify Cassandra is running via IDEA

  • If everything is configured correctly, when you run Cassandra (via idea_run.png or Run > Run...) logs should appear in the IDEA console.

    Cassandra Logs via IDEA.png

    Once cassandra is started, you can also check it's up and running by connecting to it via cqlsh

     $ ./cqlsh 
     Connected to Test Cluster at localhost:9160.
     [cqlsh 3.1.8 | Cassandra 1.2.11-SNAPSHOT | CQL spec 3.0.0 | Thrift protocol 19.36.1]
     Use HELP for help.
     cqlsh> 

Notes

Java 7 since Cassandra 2.0

Dont forget to update IntelliJ to use JDK7 or later for Cassandra versions greater than Cassandra 1.2

  • 7_JDK and Language Level Change.png

stats

If you did not check Link created IntelliJ IDEA modules to Eclipse project files in the project import dialog, you can change that later and IDEA will automatically use changes if .classpath file is regenerated using

ant generate-eclipse-files
  • 3c-project-structure.png

RunningCassandraInIDEA (last edited 2015-04-07 16:31:59 by RobertStupp)