2). 导入项目到eclipse
我们创建好了一个基本的maven项目,然后导入到eclipse中。这里我们最好已安装好了Maven的插件。
步骤如下:
File->import->Maven->ExistingMaven Projects

点击 next
填上上面新建的Maven项目的目录

点击 Finish,完成导入,如下:

3). 增加Hadoop依赖
这里我使用hadoop-1.2.1版本,在eclipse里修改文件:pom.xml
//主要是添加红色的hadoop内容
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.conan.myhadoop.mr</groupId>
<artifactId>myHadoop</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>myHadoop</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
4). 下载依赖
C:\Users\licz\workspace\myHadoop>mvn clean install
命令完成后会看到Mamen Dependencies下多出许多信赖包

项目的依赖程序,被自动加载的库路径下面
5). 从Hadoop集群环境下载hadoop配置文件
core-site.xml
hdfs-site.xml
mapred-site.xml
查看core-site.xml
<?xmlversion="1.0"?>
<?xml-stylesheettype="text/xsl"href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://nticket1:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/app/hadoop/hadoop-1.2.1/tmp</value>
</property>
</configuration>
查看hdfs-site.xml
<?xmlversion="1.0"?>
<?xml-stylesheettype="text/xsl"href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>dfs.data.dir</name>
<value>/app/hadoop/hadoop-0.20.2/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
</configuration>
查看mapred-site.xml
<?xmlversion="1.0"?>
<?xml-stylesheettype="text/xsl"href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>nticket1:9001</value>
</property>
</configuration>
保存在src/main/resources/hadoop目录下面

删除原自动生成的文件:App.java和AppTest.java
6).配置本地host,增加主节点nticket1的域名指向
修改hosts文件:
c:/Windows/System32/drivers/etc/hosts
10.1.32.91 nticket1
