Hadoop-02-03 maven和eclipse环境搭建

来源:互联网 发布:plc编程毕业论文题目 编辑:程序博客网 时间:2024/06/12 01:07

一.windows安装

1.安装maven

解压 apache-maven-3.3.9-bin.zip 直接可用 ,以解压到D盘为例子

 

2.配置setting.xml文件  本地仓库位置

 

<localRepository>D:\apache-maven-repository</localRepository>

 

本地代码库,直接把repository.zip包解压到该目录下,就不会上网去下载了

 

3.设置eclipse

window-preferences搜索maven

 

Installations

设置maven文件的位置        D:\apache-maven-3.3.9

 

User settings

设置setting.xml文件的位置    D:\apache-maven-3.3.9\conf\settings.xml

 

4.右键构建一个maven项目

 

 

 

5.设置pom.xml文件

  具体可看  https://mvnrepository.com

 

<dependencies>

<!--https://mvnrepository.com/artifact/junit/junit-->

<dependency>

    <groupId>junit</groupId>

    <artifactId>junit</artifactId>

    <version>4.9</version>

</dependency>

<!--https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client-->

<dependency>

   <groupId>org.apache.hadoop</groupId>

   <artifactId>hadoop-client</artifactId>

    <version>2.5.0</version>

</dependency>        

  </dependencies>

 

 

6.hdfs api

 

log4j:WARN Pleaseinitialize the log4j system properly.

。。。

方式一:配置文件发送

将以下配置文件copy到工程目录   src/main/resources 目录下

 

core-site.xml

core-default.xml

hdfs-site.xml

hdfs-default.xml

Log4j.properties

 

方式二:代码设置

Configuration conf =new Configuration();

conf.set("fs.defaultFS","hdfs://itcast:9000/");

 

 

原因分析:systemfile 会读取上面配置文件的信息  从而连接服务器

 

<<HdfsUtil.java>>

 

 

二.linux安装

1.安装,apache-maven-3.0.5-bin.tar.gz

解压apache-maven-3.0.5-bin.tar.gz,eclipse-jee-kepler-SR1-linux-gtk-x86_64.tar.gz 直接可用 ,以解压到 /cloud 为例子

 

2.maven配置

 

  2.0 setting.xml文件  本地仓库位置     

         直接把apache-maven-3.0.5-bin.tar.gz    包解压到该目录下,就不会上网下载了

           tar -zxvf repository.tar.gz -C /cloud/maven

          <localRepository>/cloud/maven/repository</localRepository>

 

 2.1配置环境变量

          vi /etc/profile

exportJAVA_HOME=/opt/modules/jdk1.7.0_67

exportHADOOP_HOME=/cloud/hadoop-2.5.0

exportMAVEN_HOME=/cloud/apache-maven-3.0.5

exportPATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$MAVEN_HOME/bin

 

           source /etc/profile

3.设置eclipse

window-preferences搜索maven

 

Installations

设置maven文件的位置        /cloud/apache-maven-3.3.9/

User settings

设置setting.xml文件的位置     /cloud/apache-maven-3.3.9/conf/settings.xml

 

4.右键构建一个maven项目

 

 

 

5.设置pom.xml文件

     具体可看  https://mvnrepository.com

 

<dependencies>

<!--https://mvnrepository.com/artifact/junit/junit-->

<dependency>

    <groupId>junit</groupId>

    <artifactId>junit</artifactId>

    <version>4.9</version>

</dependency>

<!--https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client-->

<dependency>

   <groupId>org.apache.hadoop</groupId>

   <artifactId>hadoop-client</artifactId>

    <version>2.5.0</version>

</dependency>        

  </dependencies>

 

 

 

6.HDFS API

 

错误

log4j:WARN Pleaseinitialize the log4j system properly.

。。。

解决

方式一:配置文件发送

将以下配置文件copy到工程目录   src/main/resources 目录下

core-site.xml

hdfs-site.xml

Log4j.properties

cd/cloud/hadoop-2.5.0/etc/hadoop

 cp hdfs-site.xml/home/kequan/workspace/HadoopDemo/src/main/resources/hdfs-site.xml

 cp core-site.xml/home/kequan/workspace/HadoopDemo/src/main/resources/core-site.xml

 cp log4j.properties  /home/kequan/workspace/HadoopDemo/src/main/resources/log4j.properties

 

方式二:代码设置

Configuration conf =new Configuration();

conf.set("fs.defaultFS","hdfs://itcast:9000/");

 

原因分析:systemfile 会读取上面配置文件的信息 (hdfs的链接) 从而连接服务器

 

 

 

0 0