1.安裝mvn(能夠省略,由於eclipse自帶maven插件)
1.1. 上傳安裝包到linux
1.2. 解壓maven安裝包java
mkdir /usr/maven tar -zxvf apache-maven-3.2.1-bin.tar.gz -C /usr/maven
1.3添加maven到環境變量linux
vim /etc/profile export JAVA_HOME=/usr/java/jdk1.7.0_55 export MAVEN_HOME=/usr/maven/apache-maven-3.2.1 export HADOOP_HOME=/cloud/hadoop-2.4.1 export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$MAVEN_HOME/bin
2.將m2.tar.gz解壓到當前用戶的家目錄下apache
tar -zxvf m2.tar.gz -C ~/
3.在Eclipse下新建maven project
3.1安裝Linux版本JavaEE的eclipse,包括如何快捷方式(create launcher)及更換快捷方式圖標vim
3.2打開eclipse,new---project---Maven---Mavern project:next---勾選create a simple project
填寫Group Id:【cn.ncst.mr】,Artifact Id:【datacount】,點擊finish完成操做網絡
3.3因爲Linux不能聯網下載依賴的Maven包,因此報錯。解決問題方式:
導入已下載好的依賴包m2.tar,解壓到root用戶的家目錄cd ~; tar -zxvf m2.tar(解壓後是隱藏文件)
而後在eclipse的maven項目datacount上右鍵Maven---Update project---OK便可解決問題。
注意:Linux機並無安裝Maven程序,只是eclipse程序自帶Maven插件而已。eclipse
3.4若是新建項目報錯,在當前項目的pom.xml中添加以下內容,刷新便可(須要有網絡)maven
<dependencies> <dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.4.3</version> </dependency> </dependencies>
4.編寫hadoop程序
4.1.HDFS程序須要(在pom.xml文件中)引入依賴:oop
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>2.4.1</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-hdfs</artifactId> <version>2.4.1</version> </dependency> </dependencies>
4.2.MR程序須要(在pom.xml文件中)引入依賴:spa
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>2.4.1</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-mapreduce-client-core</artifactId> <version>2.4.1</version> </dependency> </dependencies>