【问题标题】:Hadoop jar - System cannot find the path specifiedHadoop jar - 系统找不到指定的路径
【发布时间】:2018-01-21 13:44:39
【问题描述】:

我正在尝试使用命令通过 hadoop 运行 jar 文件

hadoop jar test.jar org.ipiran.hadoop.sample.TestMapReduce /user/data.txt /output/1.txt 4

但它返回错误

退出代码:1 异常信息:系统找不到指定的路径

我尝试不指定类,但得到了相同的结果。 我有文件 data.txt。 我的主要java代码

public int run(String[] args) throws Exception {
    Configuration conf = this.getConf();
    conf.set("fs.defaultFS", "hdfs://localhost:9000/");
    conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
    conf.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());
    conf.set("source", args[2]);
    long numUpdated = 1;
    int code = 0;
    int numIterations = 1;
    FileSystem hdfs = FileSystem.get(conf);
    while (numUpdated > 0) {
        logger.info("Iteration: " + numIterations);
        String input, output;
        Job job = Job.getInstance(conf, "word count");
        if (numIterations == 1) {
            input = args[0];
        } else {
            input = args[1] + "-" + (numIterations - 1);
        }
        output = args[1];// + "-" + numIterations;

        job.setJarByClass(TestMapReduce.class);
        job.setMapperClass(testmap.class);
        job.setReducerClass(TestReduce.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);
        FileInputFormat.addInputPath(job, new Path(input));
        FileOutputFormat.setOutputPath(job, new Path(output));
        code = job.waitForCompletion(true) ? 0 : 1;

        Counters jobCounters = job.getCounters();
        numUpdated = jobCounters.
            findCounter(MoreIterations.numUpdated).getValue();
        if (numIterations > 1) {
            hdfs.delete(new Path(input), true);
            logger.info("Updated: " + numUpdated);
        }
        numIterations += 1;
    }
    return code;
}

我使用的是 Windows 10。有人知道这里出了什么问题吗?

【问题讨论】:

  • 我不知道如何将它与hadoop代码一起应用。你能详细说明一下吗?
  • 为什么要将文件上传到/user,而不是像/user/nnnzzzaaa 这样的实际HDFS 用户文件夹?

标签: java hadoop


【解决方案1】:

您使用的是 Windows 10,但是如果您使用的是 Linux,则您正在处理它。

在Linux中“/someDir/someFile 表示根目录下的目录下有文件。

您必须将数据文件的路径更改为与 Windows 兼容的某个位置。

顺便问一下,你的机器上安装了hadoop吗?

我建议使用 linux 虚拟机,您可以使用 Cloudera 虚拟机,因为它已经安装了所有东西

https://www.cloudera.com/downloads/quickstart_vms/5-12.html

【讨论】:

  • 感谢您的回复。我确实在我的机器上安装了 hadoop。这些文件位于 hdfs 上,它使用类似于 linux 的文件系统。我使用的路径与将这些文件复制到 hdfs 时使用的路径相同。如果我错了,那么路径应该是什么样子?我无法使用 cloudera,因为我使用的是笔记本电脑,但内存不足。
  • @nnnzzzaa 您的本地文件系统上没有 /user 文件夹,因此路径不能完全相同
  • @nnnzzzaaa 如果文件预计在 HDFS 中,那么您需要使用指向文件的 hdfs 路径。通常HDFS上的文件夹是/usr/something not /user 请使用hadoop fs -cat /user/data.tx确认路径
  • 路径正确。我刚刚输入了你的命令,它打印了我的文件。
  • 我猜你可能需要尝试 hdfs://yourpath 来将它与普通的本地文件系统区分开来
猜你喜欢
  • 2020-11-11
  • 2017-11-21
  • 1970-01-01
  • 2017-10-31
  • 1970-01-01
  • 2011-02-23
  • 2018-12-12
  • 2016-04-23
相关资源
最近更新 更多