若是想经过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