eclipse导入nutch代码

1.首先下载nutch的最新版本, http://apache.etoak.com/nutch/ 本文写作时nutch的最新版本为1.1。所以本文以下所述均针对nutch1.1。(注意笔者在下载时发现该版本的src包有问题。换成bin包后正常)

2.在eclipse中新建立一个Java Project. 名字自己定义(Nutch). 选择"Create project from existing source",指向自己nutch-1.0的目录.

3.单点finish完成。这时就把nutch的整个工程全部导入到了 eclipse中了。

4.此时还需将conf文件下的所有配置文件加入到classPath中。

右键conf――>Build PathàUse as Source Folder

5.修改配置文件

conf/nutch-site.xml    <configuration>中加入以下内容。

<property>

           <name>http.agent.name</name>

           <value>test</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>

      <property>

           <name>http.agent.description</name>

           <value>test</value>

           <description>

                 Further description of our bot- this text is used in

                 the User-Agent header. It appears in parenthesis after the

                 agent name.

           </description>

      </property>

      <property>

           <name>http.agent.url</name>

           <value>www.163.com</value>

           <description>

                 A URL to advertise in the User-Agent header. This will

                 appear in parenthesis after the agent name. Custom dictates

                 that this

                 should be a URL of a page explaining the purpose and

                 behavior of this

                 crawler.

           </description>

      </property>

      <property>

           <name>http.agent.email</name>

           <value>[email protected]</value>

           <description>

                 An email address to advertise in the HTTP 'From' request

                 header and User-Agent header. A good practice is to mangle     this

                 address (e.g. 'info at example dot com') to avoid spamming.

           </description>

      </property>

conf/nutch-default.xml

<property>

            <name>plugin.folders</name>

  <value>./src/plugin</value><!—修改部分-->

conf/crawl-urlfilter.txt

    #accept hosts in MY.DOMAIN.NAME

+^http://([a-z0-9]*/.)*163.com/      ---写入想抓取的网站正则表达式

6.在工程的根目录下建立urls文件夹,其中新建一个url.txt文件,该文件中写入想抓取的网站URL,如:http://www.163.com/

7.执行nutch的 crawl命令。

至此nutch导入eclipse中运行成功。

手动复制导入nutch代码到eclipse中.(目录结构更清楚)

通过以上方式虽然可以成功的将nutch导入eclipse中,但工程目录结构极为不适合,所以笔者又以手动的方式将nutch的源代码导入eclipse中,使目录更清晰。具体步骤如下:

1.在eclipse中新建立一个Java Project. 名字自己定义(Nutch). 选择"Create New project in WorkSpace".点击完成。

2.将解压后的nutch目录下的/src/java/中的代码全部复制到新建工程中的src下。

将解压后的nutch目录下的lib、plugins、conf三个文件夹复制到新建工程的根目录下(与src同级)

3.右键工程properties, 切换到"Libraries"选择"Add Class Folder..." 按钮,从列表中选择"conf". 将 conf加入到classpath中。

4.修改配置文件

(1)conf/nutch-site.xml 同上.

(2)conf/nutch-default.xml

<property>

         <name>plugin.folders</name>

           <value> ./plugins</value><!—小心这里路径变了,笔者曾在此费了大半天时间-->

(3) conf/crawl-urlfilter.txt 同上。

(4)新建urls。同上

 

担心内存不够的话  在vm环境变量中加入  -Xms64m  -Xmx512m         

 

   Xms (minimum ammount of RAM memory for running applications)

-Xms(运行程序最小的内存限制)

-Xmx (maximum)

(最大的)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章