Nutch1.0或者Nutch1.1如何匯入MyEclipse與Eclipse

來源:互聯網
上載者:User

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代碼  
  1. <property>  
  2.   <name>http.agent.name</name>  
  3.   <value>HD nutch agent</value>  
  4.   <description></description>  
  5. </property>  
  6.   
  7. <property>  
  8.   <name>http.agent.description</name>  
  9.   <value>hpjianhua</value>  
  10. <description></description>  
  11. </property>  
  12.   
  13. <property>  
  14.   <name>http.agent.url</name>  
  15.   <value>http://www.163.com</value>  
  16.   <description></description>  
  17. </property>  
  18.   
  19. <property>  
  20.   <name>http.agent.email</name>  
  21.   <value>hpjianhua@163.com</value>  
  22.   <description></description>  
  23. </property>  

 

 

 

5.點擊Finish 來完成Nutch1.0的匯入.

 

下面在MyEclipse或者是Eclipse中對Nutch1.0進行修改以去掉項目中提示的錯誤:

 

1.      修改conf檔案夾下面的檔案:

 

1.1修改nutch-site.xml檔案:

 

 

Xml代碼  
  1. <configuration>  
  2.     <property>  
  3.       <name>http.agent.name</name>  
  4.       <value>nutch</value>  
  5.       <description></description>  
  6.     </property>  
  7.       
  8.     <property>  
  9.       <name>http.agent.description</name>  
  10.       <value>hpjianhua</value>  
  11.     <description></description>  
  12.     </property>  
  13.       
  14.     <property>  
  15.       <name>http.agent.url</name>  
  16.       <value>http://www.163.com</value>  
  17.       <description></description>  
  18.     </property>  
  19.       
  20.     <property>  
  21.       <name>http.agent.email</name>  
  22.       <value>hpjianhua@163.com</value>  
  23.       <description></description>  
  24.     </property>  
  25. </configuration>  

 

1.2修改nutch-defaul.xml檔案:

 

 

 

Xml代碼  
  1. <property>  
  2.   <name>http.agent.name</name>  
  3.   <value>HD nutch agent</value>  
  4.   <description>HTTP 'User-Agent' request header. MUST NOT be empty -   
  5.   please set this to a single word uniquely related to your organization.  
  6.   
  7.   NOTE: You should also check other related properties:  
  8.   
  9.     http.robots.agents  
  10.     http.agent.description  
  11.     http.agent.url  
  12.     http.agent.email  
  13.     http.agent.version  
  14.   
  15.   and set their values appropriately.  
  16.   
  17.   </description>  
  18. </property>  

 

 

1.3修改crawl-urlfilter.txt檔案:

 

 

 

Xml代碼  
  1. # accept hosts in MY.DOMAIN.NAME  
  2. +^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代碼  
  1. 修改—-  src\plugin\parse-rtf\src\java\org\apache\nutch\parse\rtf下RTFParseFactory.java  
  2. 添加—– import org.apache.nutch.parse.ParseResult;  
  3. 將  —– public Parse getParse(Content content) {  
  4. 改為—- public ParseResult getParse(Content content) {  
  5. 將  —- return new ParseStatus(ParseStatus.FAILED,  
  6. ParseStatus.FAILED_EXCEPTION,  
  7. e.toString()).getEmptyParse(conf);  
  8. 改為—–return new ParseStatus(ParseStatus.FAILED,  
  9. ParseStatus.FAILED_EXCEPTION,  
  10. e.toString()).getEmptyParseResult(content.getUrl(), getConf());  
  11. 將——return new ParseImpl(text,  
  12. new ParseData(ParseStatus.STATUS_SUCCESS,  
  13. title,  
  14. OutlinkExtractor.getOutlinks(text, this.conf),  
  15. content.getMetadata(),  
  16. metadata));  
  17. 改為——return ParseResult.createParseResult(content.getUrl(),  
  18. new ParseImpl(text,  
  19. new ParseData(ParseStatus.STATUS_SUCCESS,  
  20. title,  
  21. OutlinkExtractor.getOutlinks(text, this.conf),  
  22. content.getMetadata(),  
  23. metadata)));  
  24. 修改——src\plugin\parse-rtf\src\test\org\apache\nutch\parse\rtf下的TestRTFParser.java  
  25. 將—–parse = new ParseUtil(conf).parseByExtensionId(“parse-rtf”, content);  
  26. 改為—-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為最大記憶體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.