Java org.apache.hadoop.mapred.filealreadyexistException

Java org.apache.hadoop.mapred.filealreadyexistException,java,hadoop,Java,Hadoop,我试图在Hadoop中运行给定的示例程序 当我尝试运行它时,我得到一个org.apache.hadoop.mapred.FileAlreadyExistsException emil@psycho-O:~/project/hadoop-0.20.2$ bin/hadoop jar jar_files/wordcount.jar org.myorg.WordCount jar_files/wordcount/input jar_files/wordcount/output 11/02/06 14:

我试图在Hadoop中运行给定的示例程序

当我尝试运行它时,我得到一个org.apache.hadoop.mapred.FileAlreadyExistsException

emil@psycho-O:~/project/hadoop-0.20.2$ bin/hadoop jar jar_files/wordcount.jar org.myorg.WordCount jar_files/wordcount/input jar_files/wordcount/output
11/02/06 14:54:23 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
11/02/06 14:54:23 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
Exception in thread "main" org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory file:/home/emil/project/hadoop-0.20.2/jar_files/wordcount/input already exists
    at org.apache.hadoop.mapred.FileOutputFormat.checkOutputSpecs(FileOutputFormat.java:111)
    at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:772)
    at org.apache.hadoop.mapred.JobClient.submitJob(JobClient.java:730)
    at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:1249)
    at org.myorg.WordCount.main(WordCount.java:55)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:156)
emil@psycho-O:~/project/hadoop-0.20.2$ 
我从/home/emil/project/hadoop-0.20.2/jar_files/wordcount/input获取输入文件file01和file02。当我在谷歌上搜索时,我发现这样做是为了防止重复执行相同的任务。但在我的例子中,是输入文件导致了异常。 我的命令是否有任何错误,因为我没有看到任何帖子出现与wordcount问题相同的错误。 我是java的新手


这可能是什么原因

如果作业运行一次,则必须删除您提供的输出目录。
这个应该适合你

bin/hadoop fs -rmr jar_files/wordcount/output
编辑

我误解了创建者,以为是关于hadoop示例jar中的worcount示例。你能在课堂上提供源代码吗
org.myorg.WordCount
我也面临同样的问题。我花了一段时间才弄清楚到底发生了什么。主要问题是您无法附加调试器以找出传递的值

您正在代码中使用args[0]作为输入,args[1]作为输出文件夹

现在,如果您使用的是新框架,其中使用的是工具类的run方法中的命令行,args[0]是正在执行的程序的名称,在本例中为WordCount

args[1]是您指定的输入文件夹的名称,该文件夹由程序映射到输出文件夹,因此您会看到异常

因此,解决方案是:


使用args[1]和args[2]。

我刚刚遇到了这个问题,我发现我必须同时执行Sandeep和Thomas所说的操作:在示例代码中使用args[1]和args[2],并确保输出目录不存在,不管示例怎么说。

是的。我遇到了同样的问题。当我删除org.myorg.WordCount时,它运行得很好

编辑:

FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));

作业需要的唯一输入是输入和输出路径

这是为了防止覆盖以前的结果。 创建和设置作业时,可以清理和删除输出路径:

public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    Job job = Job.getInstance(conf, "word count");
    job.setJarByClass(WordCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    TextInputFormat.addInputPath(job,new Path(args[0]));
    FileSystem.get(conf).delete(new Path(args[1]),true);
    TextOutputFormat.setOutputPath(job, new Path(args[1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
}

代码与apache站点中给出的代码相同。上面提到的错误是在我尝试以与他们所说的相同的方式运行程序时报告的,即,$bin/hadoop jar/usr/joe/wordcount.jar org.myorg.wordcount/usr/joe/wordcount/input/usr/joe/wordcount/output。但是,如果我将其更改为$bin/hadoop-jar/usr/joe/wordcount.jar/usr/joe/wordcount/input/usr/joe/wordcount/output,它运行良好。怎么会??另外,请推荐一个学习Hadoop的好地方、电子书等谢谢,我的问题是args[]