若是想經過eclipse來調試或者查看Cassandra的代碼,將其project導入到eclipse之中不愧是個好選擇。下面將講述將2.0.8 版本導入elcipse的過程。html
該篇文章主要參考的官方文檔爲:http://wiki.apache.org/cassandra/RunningCassandraInEclipsejava
爲了快速訪問,轉載到這裏:http://www.cnblogs.com/chang290/p/3837102.htmlnode
1、準備工做apache
一、去官網下載Cassandra源碼包:apache-cassandra-2.0.8-src.tar.gz。eclipse
二、解壓出來會有一個apache-cassandra-2.0.8-src目錄,將該目錄修改爲本身想要的project名稱(注意這個目錄的名稱與project名稱必定要一致,所以在產生elipse文件時會使用該絕對目錄名稱),好比我這裏叫作 cassandra-208-trunk。測試
三、進入到cassandra-208-trunk目錄,執行以下兩個命令: ui
ant build
ant generate-eclipse-files
四、在ant build之中會須要下載一些文件,所以該步驟須要一些時間。spa
2、建立java project3d
一、打開eclipse建立一個java project,project name叫作 cassandra-208-trunk (注意這個名稱必須和目錄名一致)調試
二、點擊新建立的cassandra-208-trunk,鼠標右鍵,進入Properties頁面
在左邊欄選擇Java Build Path,右邊選擇Source選項卡,設置好Source folders 與 output folder,如圖所示:
修改完成以後點擊OK,保存。
三、運行配置
點擊新建立的cassandra-208-trunk,鼠標右鍵,選擇 Run as -> Run Configurations
1)配置Main class,在Project框中選擇Cassandra-208-trunk,在Main class框中選擇 org.apache.cassandra.service.CassandraDaemon
2)配置啓動參數
在Program arguments框中輸入:
-Dcassandra.config=file:XXXXXX/cassandra-208-trunk/conf/cassandra.yaml ----其中的XXXXX爲項目所在的路徑
-Dcassandra-foreground
-ea -Xmx2G ----配置堆內存,根據實際配置
-Dlog4j.configuration=file:XXXXXX/cassandra-208-trunk/conf/log4j-server.properties ----其中的XXXXX爲項目所在的路徑
在VM arguments之中輸入以下內容:
-Djava.rmi.server.hostname=127.0.0.1 ----爲運行nodetool使用
-Dcom.sun.management.jmxremote.port=7199 ----爲運行nodetool使用的默認端口
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
3、運行測試
完成上述的配置以後,就能夠啓動項目了,輸出以下:
14/07/11 09:59:00 INFO db.Memtable: Completed flushing build/test/cassandra/data/system/local/system-local-jb-9-Data.db (110 bytes) for commitlog position ReplayPosition(segmentId=1405043940005, position=174117) 14/07/11 09:59:00 INFO service.StorageService: Node /127.0.0.1 state jump to normal 14/07/11 09:59:00 INFO compaction.CompactionTask: Compacted 4 sstables to [build/test/cassandra/data/system/local/system-local-jb-10,]. 1,079 bytes to 531 (~49% of original) in 16ms = 0.031650MB/s. 4 total partitions merged to 1. Partition merge counts were {4:1, }
而後進入到項目目錄 cassandra-208-trunk/bin 運行 ./nodetool status 輸出以下:
Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Owns (effective) Host ID Token Rack UN 127.0.0.1 98.02 KB 100.0% 53e17e1a-5785-43dc-b724-dd3188f1b822 43e797990015319dfe8cd742dbbe788d rack1