大数据开发之在idea中开发第一个hadoop程序

第一步 新建一个maven 项目

第二步 在pom文件中导入相应的依赖


<project xmlns="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.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>bigdataartifactId>
        <groupId>org.hadoop.examplegroupId>
        <version>1.0-SNAPSHOTversion>
    parent>
    <modelVersion>4.0.0modelVersion>

    <artifactId>example1_wordcountartifactId>

    <dependencies>
        <dependency>
            <groupId>junitgroupId>
            <artifactId>junitartifactId>
            <version>RELEASEversion>
        dependency>
        <dependency>
            <groupId>org.apache.logging.log4jgroupId>
            <artifactId>log4j-coreartifactId>
            <version>2.8.2version>
        dependency>
        <dependency>
            <groupId>org.apache.hadoopgroupId>
            <artifactId>hadoop-commonartifactId>
            <version>3.2.2version>
        dependency>
        <dependency>
            <groupId>org.apache.hadoopgroupId>
            <artifactId>hadoop-clientartifactId>
            <version>3.2.2version>
        dependency>
        <dependency>
            <groupId>org.apache.hadoopgroupId>
            <artifactId>hadoop-hdfsartifactId>
            <version>3.2.2version>
        dependency>
    dependencies>

    <build>
        <plugins>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>3.8.0version>
                <configuration>
                    <source>1.8source>
                    <target>1.8target>
                    <encoding>utf-8encoding>
                configuration>
            plugin>
        plugins>
    build>

project>

第三步 写一个hadoop程序

package org.hadoop.example.wordcount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * @author: 
 * @date: 2022/12/16/15:50
 */
public class Application {
     public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException {
         Configuration conf=new Configuration();//加载配置项
         FileSystem fs = FileSystem.get(new URI("hdfs://localhost:9000/"), conf,"Administrator");//加载文件系统实例
         fs.mkdirs(new Path("/yqw"));//新建文件夹
     }
}

第三步 查看目录是否创建成功

大数据开发之在idea中开发第一个hadoop程序_第1张图片

你可能感兴趣的:(大数据开发教程,hadoop,大数据,intellij-idea)