Windows下myeclipse 安裝 Nutch1.2(終於找到個不報錯的)
1.下載並安裝cygwin,安裝和環境配置不細說了。將%CYGWIN_HOME%\bin加到path中。
2.匯入到Eclipse中
①在Eclipse中添加File > New > Project > Java project。
project name隨便,選擇 “Create project from existing source” ,在browse中選nutch的解壓路徑,如D:\nutch-1.2
②在“Add Class Folder” 中選擇 conf 檔案夾。
③然後再定義一個“Default ouput folder” ,名稱任意。注意不能選bin檔案夾,因為如果選了bin檔案夾做為Default output folder 編譯時間會清空該檔案夾,bin下的其他檔案會被刪掉,導致其他問題。
④Finish.
3.修改Nutch的設定檔,這裡以抓取www.163.com為例。
①修改D:\nutch-1.2\conf下的nutch-site.xml配置
- <?xml version="1.0"?>
- <?xml-stylesheet href="configuration.xsl"?>
- <!-- Put site-specific property overrides in this file. -->
- <configuration>
- <property>
- <name>http.agent.name</name>
- <value>nutch-1.2</value>
- <description>HTTP 'User-Agent'</description>
- </property>
- <property>
- <name>searcher.dir</name>
- <value>D:\nutch-1.2\crawl</value>
- <description>Path to root of crawl.</description>
- </property>
- </configuration>
複製代碼
②修改在D:\nutch-1.2\conf下的crawl-urlfilter.txt
- # accept hosts in MY.DOMAIN.NAME
- +^http://([a-z0-9]*\.)*163.info/
- # skip everything else
複製代碼
③修改D:\nutch-1.2\conf下的nutch-default.xml
- <property>
- <name>plugin.folders</name>
- <value>./src/plugin</value>
- <description>Directories where nutch plugins are located. Each
- element may be a relative or absolute path. If absolute, it is used
- as is. If relative, it is searched for on the classpath.</description>
- </property>
複製代碼
④在D:\nutch-1.2\下,建立名為urls的檔案夾,並在檔案夾內建立url.txt的文本,寫入
http://www.163.com/
複製代碼
4. 在Eclipse裡運行Nutch
①Run-open run dialog
②name隨便寫
③在main class填寫
- org.apache.nutch.crawl.Crawl
複製代碼
④arguments填寫
- urls -dir crawl -depth 3 -topN 50
複製代碼
⑤在VM arguments填寫
- -Dhadoop.log.dir=logs -Dhadoop.log.file=hadoop.log
複製代碼
OK,運行,看Nutch在爬啊爬啊。