Maven的安装配置

来源:互联网 发布:骁龙835支持5g网络吗 编辑:程序博客网 时间:2024/05/11 10:55

安装及配置

maven是干嘛的?最主要的(只是最主要的)是可以帮你解决jar包依赖问题,自动帮你到jar

1.安装maven

2.配置setting.xml文件

       <localRepository></localRepository>

 

localRepository:本地仓库。

当要用到一些jar包的时候maven会先从本地仓库里面找,如果本地仓库里没有,就会从网上下载下来并且加载到本地仓库中,这样下次用的时候就不需要再去下载了

3.设置eclipse

       window-preferences搜索maven

      

       Installations

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

  

 

 

       User setting

       设置setting.xml文件的位置(复制一份到repository所在文件夹的位置)

这里两个填的是所在这个位置的settingsrepository

  

4.右键构建一个maven项目

1、

2、

3、然后就finish

5.设置pom.xml文件

当这个项目启动的时候,它会先读pom.xml文件,在pom.xml文件里配置一些依赖(dependencies),依赖也就是说meaven可以帮你解决jar包依赖问题

 

方法:

1、百度搜索mavenrepository,进入mvnrepository.com网站

2、需要哪个jar包直接搜索

3、搜索之后进入,选择版本,复制maven

 

 

复制到pom.xml文件,保存,就会自动导入jar包了

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

      

HDFS API

 

 

public classHDFSDemo {

       FileSystem fs = null;

       @Before(为了获取这个hdfs文件系统)

       public void get() throws Exception{

              //1.获取FileSystem对象 get()

              fs = FileSystem.get(newURI("hdfs://nicole.com.cn:8020"), new Configuration(),"nicole");

                    

       }

URInamenode地址

       /*

        * 测试下载文件

        */

       @Test

       public void testDownLoad() throwsException{

                     //2.使用open方法获取inputstream

              FSDataInputStream in = fs.open(newPath("/nicole/input/for.sh"));

              FileOutputStream out = newFileOutputStream("e://for.shs");

              /*

               * true:拷贝完成自动关闭

               */

              IOUtils.copyBytes(in, out, 4096,true);

                    

       }

      

       /*

        * 测试上传文件

        */

       @Test

       public void testUpload() throwsException{

              FSDataOutputStream out =fs.create(new Path("/nicole/for.sh"));

              FileInputStream in = newFileInputStream("pom.xml");

              IOUtils.copyBytes(in, out, 4096,true);

       }

      

       /*

        * 测试删除文件

        */

       @Test

       public void testDEL() throws Exception{

              boolean delete = fs.delete(newPath("/nicole/for.sh"), true);

              System.out.println(delete);

       }

      

       /*

        * 创建文件夹

        */

       @Test

       public void testMkdir() throws Exception{

              boolean mkdirs = fs.mkdirs(newPath("/nicole/mkdir"));

              System.out.println(mkdirs);

       }

      

}

 

0 0