在Eclipse中運行Nutch2.3,eclipsenutch2.3
參考http://wiki.apache.org/nutch/RunNutchInEclipse
一、環境準備
1、下載nutch2.3原始碼
wget http://mirror.bit.edu.cn/apache/nutch/2.3/apache-nutch-2.3-src.tar.gz
或者下載正在開發中的最新版本
svn co https://svn.apache.org/repos/asf/nutch/branches/2.x
2、選擇使用的資料庫類型,以hbase為例
在conf/nutch.xml中增加以下屬性:
<property> <name>storage.data.store.class</name> <value>org.apache.gora.hbase.store.HBaseStore</value> <description>Default class for storing data</description> </property>
3、在ivy/ivy.xml中增加與hbase相關的依賴項,此項本已存在,但被注釋掉,將注釋去掉即可
<dependency org="org.apache.gora" name="gora-hbase" rev="0.5" conf="*->default” />
注意,rev=0.5對應hbase0.94,rev=0.3對應hbase0.90.4
4、在nutch.xml中增加以下3個屬性
<property> <name>http.agent.name</name> <value>My Nutch Spider</value> </property><property> <name>http.robots.agents</name> <value>none</value> </property><property> <name>plugin.folders</name> <value>/Users/liaoliuqing/0_Search/1_Nutch/1_Official/apache-nutch-2.3/build/plugins</value> </property>
其中plugin.folders的值為$NUTCH_HOME/build/plugins
5、執行ant eclipse
二、匯入project
1、匯入project
2、在build path中,將apche-nutch-2.3/conf放到最上面,即點擊top按鍵
三、運行程式
1、Run as ----> Run configuration,選擇project與主類
2、填寫參數
/Users/liaoliuqing/Downloads/seed.txt
-Dhadoop.log.dir=logs -Dhadoop.log.file=hadoop.log
3、點擊run,輸出結果如下:
InjectorJob: starting at 2015-01-28 16:27:43
InjectorJob: Injecting urlDir: /Users/liaoliuqing/Downloads/seed.txt
InjectorJob: Using class org.apache.gora.hbase.store.HBaseStore as the Gora storage class.
InjectorJob: total number of urls rejected by filters: 0
InjectorJob: total number of urls injected after normalization and filtering: 1
Injector: finished at 2015-01-28 16:27:47, elapsed: 00:00:04
注意,在運行程式前,本機需要先啟動hbase。
4、查看hbase中的資料
hbase(main):003:0> scan 'webpage'ROW COLUMN+CELL com.163.www:http/ column=f:fi, timestamp=1422433667377, value=\x00'\x8D\x00 com.163.www:http/ column=f:ts, timestamp=1422433667377, value=\x00\x00\x01K/\xA7:\x14 com.163.www:http/ column=mk:_injmrk_, timestamp=1422433667377, value=y com.163.www:http/ column=mk:dist, timestamp=1422433667377, value=0 com.163.www:http/ column=mtdt:_csh_, timestamp=1422433667377, value=?\x80\x00\x00 com.163.www:http/ column=s:s, timestamp=1422433667377, value=?\x80\x00\x00 1 row(s) in 0.2970 seconds