You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by Apache Wiki <wi...@apache.org> on 2013/10/24 13:25:00 UTC

[Cassandra Wiki] Update of "RunningCassandraInIDEA" by JonathanEllis

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Cassandra Wiki" for change notification.

The "RunningCassandraInIDEA" page has been changed by JonathanEllis:
https://wiki.apache.org/cassandra/RunningCassandraInIDEA?action=diff&rev1=22&rev2=23

  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.)
+ 
+ You can create an IntelliJ project in just two steps:
+ 
+  1. Run "ant generate-eclipse-files"
+  1. File -> Import Project
+ 
+ If you want to get up close and personal with setting it up manually instead of "cheating" like that, read on...
  
  <<TableOfContents>>
  
  = Setup Cassandra as a project =
+ Preconditions: JDK6 and Ant (http://ant.apache.org/)
  
- Preconditions: JDK6 and Ant (http://ant.apache.org/) 
+ IDEA will generally set the project up properly for you (you'll need to run some ant targets and add a couple of folders as "content roots").
  
+ Open IDEA and Select "Check out from Version Control" under "Quick Start" and select 'Git' or 'Subversion' (this tutorial will use Git). (The URL to the Apache Cassandra svn is https://svn.apache.org/repos/asf/cassandra/trunk, the 'Git Repository URL' is git://git.apache.org/cassandra.git)
- IDEA will generally set the project up properly for you (you'll need to run some ant targets and add a couple of folders as "content roots"). 
- 
- Open IDEA and Select "Check out from Version Control" under "Quick Start" and select 'Git' or 'Subversion' (this tutorial will use Git).
- (The URL to the Apache Cassandra svn is https://svn.apache.org/repos/asf/cassandra/trunk, the 'Git Repository URL' is git://git.apache.org/cassandra.git)
-  
  
  {{attachment:CheckOutFromVersionControl-1.png}}
  
+ Parent directory is where IDEA will place the Cassandra checkout/clone. Press Clone to engage the checkout/clone (be patient, will take some time).  Answer 'Yes' to "Would you like to create an IntelliJ IDEA project for the sources you have checked out to /Users/schildmeijer/workspace/cassandra?"
- Parent directory is where IDEA will place the Cassandra checkout/clone.
- Press Clone to engage the checkout/clone (be patient, will take some time). 
- Answer 'Yes' to "Would you like to create an IntelliJ IDEA project for the sources you have checked out to /Users/schildmeijer/workspace/cassandra?"
  
  {{attachment:CloneRepository-2.png}}
  
@@ -26, +28 @@

  
  {{attachment:CreateProjectFromExistingSources-3.png}}
  
+ Pick an appropriate name for the new project (e.g cassandra) 'Project files location' is where on the file system IDEA will create your Java project.
- Pick an appropriate name for the new project (e.g cassandra)
- 'Project files location' is where on the file system IDEA will create your Java project.
  
  {{attachment:NewProject-4.png}}
  
  Add the following Java source files to your module.
+ 
-   * interface/thrift/gen-java
+  * interface/thrift/gen-java
-   * src/java
+  * src/java
-   * test/unit
+  * test/unit
  
  {{attachment:NewProjectChooseModules-5.png}}
  
  Press 'Next' followed by 'Finish' after you have reviewed the suggested module structure. I recommend to only have one module (Cassandra).
  
+ {{attachment:NewProjectReviewLibrariesFound-6.png}} {{attachment:NewProjectReviewModuleStructure-7.png}}
- {{attachment:NewProjectReviewLibrariesFound-6.png}}
- {{attachment:NewProjectReviewModuleStructure-7.png}}
  
  Your project will be now imported into the IDEA project workspace. Wait until the project indexing is done. (This might take some time depending on your computer)
  
  Your IDEA project workspace should now look something like this:
  
  {{attachment:InitialProjectWorkspace-8.png}}
-  
+ 
- Whats left now is to generate the Command Line Interface (CLI) grammar by ANTLR, add the "conf" folder to your sources, so that log4j properties can be found, generate the avro code and finally add these folders as "content roots". 
+ Whats left now is to generate the Command Line Interface (CLI) grammar by ANTLR, add the "conf" folder to your sources, so that log4j properties can be found, generate the avro code and finally add these folders as "content roots".
  
  First we will generate some code (CLI grammar, avro bindings, thrift bindings). This is where ant enters the building.
  
+ Press the 'Ant Build' tab (far to the right), then 'Add' (the plus sign) and locate the build.xml in your cassandra project folder. Run the ant 'build' target by double clicking on it (this should hopefully generate all the code necessary to run cassandra in IDEA). (Press no if IDEA asks you to add some project specific files to git/svn version control).
- Press the 'Ant Build' tab (far to the right), then 'Add' (the plus sign) and locate the build.xml in your cassandra project folder.
- Run the ant 'build' target by double clicking on it (this should hopefully generate all the code necessary to run cassandra in IDEA).
- (Press no if IDEA asks you to add some project specific files to git/svn version control).
  
  {{attachment:Ant-9.png}}
  
- Next step is to add the "conf" folder.
- Choose 'View as: Packages" and right click on your cassandra project and pick 'Module Settings'. Go to dependencies and press 'Add' then 'Single-Entry Module Library...' Now locate the conf folder and press 'Ok'. 
+ Next step is to add the "conf" folder. Choose 'View as: Packages" and right click on your cassandra project and pick 'Module Settings'. Go to dependencies and press 'Add' then 'Single-Entry Module Library...' Now locate the conf folder and press 'Ok'.
  
  {{attachment:Single-EntryModuleDependency-10.png}}
  
+ Now it's time to add avro and thrift generated java files as 'content roots'. Once again, right click on the cassandra project in the 'View as: Packages" perspective and choose 'Module Settings' This time you press 'Add Content Root' and locate "interface/avro/gen-java", do the same for "interface/thrift/gen-java"
- Now it's time to add avro and thrift generated java files as 'content roots'.
- Once again, right click on the cassandra project in the 'View as: Packages" perspective and choose 'Module Settings'
- This time you press 'Add Content Root' and locate "interface/avro/gen-java", do the same for "interface/thrift/gen-java"
  
+ {{attachment:ContentRootAvro-11.png}} {{attachment:ContentRootThrift-12.png}}
- {{attachment:ContentRootAvro-11.png}}
- {{attachment:ContentRootThrift-12.png}}
  
  One final thing needs to be done in this view; choose the cassandra/src content root, right click on "gen-java" and click 'Sources'.
  
@@ -78, +73 @@

  '''Update''' If you still see some errors popping up, right click on the cassandra project in the 'View as: Packages" perspective and choose 'Module Settings'. Go to Libraries(on the left), click "Attach Jar Directories.." and add build/lib/jars directory. Now when you rebuild your project, all errors should go away.
  
  = Create a Cassandra application's RUN configuration =
- 
  Create a new application called cassandra (e.g Run -> Edit Configurations -> Add new configuration (insert) -> Application)
  
   * Main class
@@ -86, +80 @@

  {{{
   org.apache.cassandra.thrift.CassandraDaemon
  }}}
+  * VM Parameters for Cassandra up to 6.0
  
-  * VM Parameters for Cassandra up to 6.0
  {{{
   -Dcassandra-foreground -Dstorage-config=@@@ -ea -Xmx1G
  }}}
- 
  Replace @@@ above with the path to your conf folder, eg mine is "/Users/schildmeijer/workspace/cassandra/conf". The flags above are taken from the cassandra shell script.
  
  * VM Parameters for Cassandra 7.0
+ 
  {{{
  -Dcassandra-foreground -Dcassandra.config=@@@ -ea -Xmx1G
  }}}
- 
- Replace @@@ above with the path to your cassandra.yaml as a URI, eg mine is "file:///home/edward/idea/conf/cassandra.yaml". 
+ Replace @@@ above with the path to your cassandra.yaml as a URI, eg mine is "file:///home/edward/idea/conf/cassandra.yaml".
- 
  
   * Working Directory
  
- eg mine is "/Users/schildmeijer/workspace/cassandra" 
+ eg mine is "/Users/schildmeijer/workspace/cassandra"
- 
  
  {{attachment:EditConfigurations-14.png}}
  
  Review and Modify storage-conf.xml and log4j.properties accordingly, as in certain cases directory creation of /var/cassandra fails due to ACLs of execution context
  
  storage-conf.xml
+ 
  {{{
      Directories: Specify where Cassandra should store different data on disk
           Keep the data disks and the CommitLog disks separate for best performance
-     
+ 
      <CommitLogDirectory>/var/cassandra/commitlog</CommitLogDirectory>
      <DataFileDirectories>
          <DataFileDirectory>/var/cassandra/data</DataFileDirectory>
@@ -123, +115 @@

      <CalloutLocation>/var/cassandra/callouts</CalloutLocation>
      <BootstrapFileDirectory>/var/cassandra/bootstrap</BootstrapFileDirectory>
      <StagingFileDirectory>/var/cassandra/staging</StagingFileDirectory>
+ }}}
+ appender in log4j.properties
  
+ {{{
+ log4j.appender.R.File=/var/cassandra/logs/system.log
  }}}
- 
- appender in log4j.properties
- {{{
- 
- log4j.appender.R.File=/var/cassandra/logs/system.log
- 
- }}}
- 
- 
  = Verify that it runs from IDEA =
- 
  When you start the app it should look similar to cmd line start, eg mine looks like this:
  
  {{{
@@ -167, +153 @@

  DEBUG 18:49:28,737 attempting to connect to /127.0.0.1
   INFO 18:49:28,800 Binding thrift service to localhost/127.0.0.1:9160
  }}}
- 
  Try running the cassandra-cli as per CassandraCli, and you should be able to connect to localhost/9160.
  
  = Project code style =
- 
  An unofficial project code style which should make it easier to conform to the project's CodeStyle is here: [[attachment:projectCodeStyle.xml]]