Windows下myeclipse 安装 Nutch1.2(终于找到个不报错的)

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配置

  1. <?xml version="1.0"?>
  2. <?xml-stylesheet href="configuration.xsl"?>
  3. <!-- Put site-specific property overrides in this file. -->
  4. <configuration>

  5. <property>
  6.   <name>http.agent.name</name>
  7.   <value>nutch-1.2</value>
  8.   <description>HTTP 'User-Agent'</description>
  9. </property>

  10. <property>
  11.   <name>searcher.dir</name>
  12.   <value>D:\nutch-1.2\crawl</value>
  13.   <description>Path to root of crawl.</description>
  14. </property>

  15. </configuration>
复制代码

②修改在D:\nutch-1.2\conf下的crawl-urlfilter.txt

  1. # accept hosts in MY.DOMAIN.NAME
  2. +^http://([a-z0-9]*\.)*163.info/ 
  3. # skip everything else
复制代码

③修改D:\nutch-1.2\conf下的nutch-default.xml

  1. <property>
  2.   <name>plugin.folders</name>
  3.   <value>./src/plugin</value>
  4.   <description>Directories where nutch plugins are located.  Each
  5.   element may be a relative or absolute path.  If absolute, it is used
  6.   as is.  If relative, it is searched for on the classpath.</description>
  7. </property>
复制代码

④在D:\nutch-1.2\下,建立名为urls的文件夹,并在文件夹内建立url.txt的文本,写入

  1. http://www.163.com/
复制代码

4. 在Eclipse里运行Nutch 

①Run-open run dialog 

②name随便写 

③在main class填写

  1. org.apache.nutch.crawl.Crawl
复制代码

④arguments填写

  1. urls -dir crawl -depth 3 -topN 50
复制代码

⑤在VM arguments填写

  1. -Dhadoop.log.dir=logs -Dhadoop.log.file=hadoop.log
复制代码

OK,运行,看Nutch在爬啊爬啊。

原文地址:https://www.cnblogs.com/cy163/p/2911112.html