Nutch1.0或者Nutch1.1如何匯入MyEclipse與Eclipse
今天浪費了一天的時間花費在這上面,一開始是用Nutch1.1匯入在MyEclipse與Eclipse中的,不斷的嘗試,不斷的調試,上網查閱了太多的文章了,發現按他們每一種的方式都會出錯,最後還是跟人交流之後,用自己的方式嘗試成功了.好了不費話了.下面說說如何成功匯入Nutch1.0而不會出錯.
前期準備工作及匯入步驟:
1.下載Cygwin工具:http://www.cygwin.com並安裝Cygwin.安裝成功後,記得在我的電腦屬性中配置環境變數:
編輯path屬性,加入d:cygwin/bin到path中.
2.下載nutch軟體包:
http://labs.renren.com/apache-mirror//nutch/一般下載bin包即可.
3.解壓剛下載下來的nutch軟體包.如,解壓位置為:D:\nutch-1.04.在Eclipse或者是在MyEclipse中建立一個Java Project項目, 名字自己定義(Nutch). 選擇”Create project from existing source”,指向自己nutch-1.0的目錄.
4.點擊下一步,切換到”Libraries”選擇”Add Class Folder…” 按鈕,從列表中選擇”conf”. —->Default Output floder —->Brower-à從Create New Folder中…建立一個新檔案夾 output.(這一步跟網上的所有辦法都不一樣.).
注意:修改output檔案夾下面的nutch-site.xml檔案:
Xml代碼
- <property>
- <name>http.agent.name</name>
- <value>HD nutch agent</value>
- <description></description>
- </property>
-
- <property>
- <name>http.agent.description</name>
- <value>hpjianhua</value>
- <description></description>
- </property>
-
- <property>
- <name>http.agent.url</name>
- <value>http://www.163.com</value>
- <description></description>
- </property>
-
- <property>
- <name>http.agent.email</name>
- <value>hpjianhua@163.com</value>
- <description></description>
- </property>
5.點擊Finish 來完成Nutch1.0的匯入.
下面在MyEclipse或者是Eclipse中對Nutch1.0進行修改以去掉項目中提示的錯誤:
1. 修改conf檔案夾下面的檔案:
1.1修改nutch-site.xml檔案:
Xml代碼
- <configuration>
- <property>
- <name>http.agent.name</name>
- <value>nutch</value>
- <description></description>
- </property>
-
- <property>
- <name>http.agent.description</name>
- <value>hpjianhua</value>
- <description></description>
- </property>
-
- <property>
- <name>http.agent.url</name>
- <value>http://www.163.com</value>
- <description></description>
- </property>
-
- <property>
- <name>http.agent.email</name>
- <value>hpjianhua@163.com</value>
- <description></description>
- </property>
- </configuration>
1.2修改nutch-defaul.xml檔案:
Xml代碼
- <property>
- <name>http.agent.name</name>
- <value>HD nutch agent</value>
- <description>HTTP 'User-Agent' request header. MUST NOT be empty -
- please set this to a single word uniquely related to your organization.
-
- NOTE: You should also check other related properties:
-
- http.robots.agents
- http.agent.description
- http.agent.url
- http.agent.email
- http.agent.version
-
- and set their values appropriately.
-
- </description>
- </property>
1.3修改crawl-urlfilter.txt檔案:
Xml代碼
- # accept hosts in MY.DOMAIN.NAME
- +^http://([a-z0-9]*\.)*163.com/
如果是Nutch1.1可以跳過下面的2 , 3, 4步,直接跑到第5步繼續!
2. 下載MP3跟rtf的jar檔案
http://nutch.cvs.sourceforge.net/nutch/nutch/src/plugin/parse-mp3/lib/,
http://nutch.cvs.sourceforge.net/nutch/nutch/src/plugin/parse-rtf/lib/
分別拷貝到src/plugin/parse-mp3/lib 和 src/plugin/parse-rtf/lib/檔案夾下
3. 重新整理幾下,右鍵選擇工程檔案夾,選擇Build Path->Configure Build Path…在彈出的視窗上,切換到Libraries,選擇Add Jars…,添加剛才下載的jar檔案到工程。
4.到這一步,一般的工程都會有兩個錯誤,nutch的official 1.0 release版本中,這兩個問題因為licensing issues沒有修複。
接下來的就是最關鍵的部分了。
Java代碼
- 修改—- src\plugin\parse-rtf\src\java\org\apache\nutch\parse\rtf下RTFParseFactory.java
- 添加—– import org.apache.nutch.parse.ParseResult;
- 將 —– public Parse getParse(Content content) {
- 改為—- public ParseResult getParse(Content content) {
- 將 —- return new ParseStatus(ParseStatus.FAILED,
- ParseStatus.FAILED_EXCEPTION,
- e.toString()).getEmptyParse(conf);
- 改為—–return new ParseStatus(ParseStatus.FAILED,
- ParseStatus.FAILED_EXCEPTION,
- e.toString()).getEmptyParseResult(content.getUrl(), getConf());
- 將——return new ParseImpl(text,
- new ParseData(ParseStatus.STATUS_SUCCESS,
- title,
- OutlinkExtractor.getOutlinks(text, this.conf),
- content.getMetadata(),
- metadata));
- 改為——return ParseResult.createParseResult(content.getUrl(),
- new ParseImpl(text,
- new ParseData(ParseStatus.STATUS_SUCCESS,
- title,
- OutlinkExtractor.getOutlinks(text, this.conf),
- content.getMetadata(),
- metadata)));
- 修改——src\plugin\parse-rtf\src\test\org\apache\nutch\parse\rtf下的TestRTFParser.java
- 將—–parse = new ParseUtil(conf).parseByExtensionId(“parse-rtf”, content);
- 改為—-parse = new ParseUtil(conf).parseByExtensionId(“parse-rtf”, content).get(urlString); 到這一步,eclipse上面的工程就會沒有錯誤了 .
5.在nutch1.0的目錄下建立立一個檔案夾urls,然後再在urls中建立一個文字檔url. 寫上連結。注意後面要有 “/”.
6.運行Nutch1.0:
選擇Run->Run As->Java Application在彈出的Select Java Application上選擇Crawl-org.apache.nutch.crawl. 接下來,
選擇 Run->Run Configurations…在左邊的Java Application下面會有Crawl這一項,選擇它,
切換到Arguments,Program Arguments的內容就是要設定的參數,填上urls -dir crawl -depth 3 -topN 50(這裡視自己的具體情況而定,urls為連結)
在VM arguments下面填上-Dhadoop.log.dir=logs -Dhadoop.log.file=hadoop.log.
直接運行吧:看在你的控制台上出現資訊了沒.
注意:關於Java Heap Size的問題,查看logs/hadoop.log或控制台輸出,如果出現類似java.lang.OutOfMemoryError: Java heap space語句,
解決方案:
設定Eclipse -> Window -> Preferences -> Java -> Installed JREs -> edit -> Default VM arguments
7.設定為-Xms256m -Xmx1024m,其中Xms為最小記憶體,Xmx為最大記憶體