org.apache.hadoop.mapred.FileAlreadyExistsException

emi*_*jho 13 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: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$ 
Run Code Online (Sandbox Code Playgroud)

它来自/home/emil/project/hadoop-0.20.2/jar_files/wordcount/input,我将输入文件file01和file02.当我用Google搜索时,我发现这样做是为了防止重新执行相同的任务.但在我的情况下,它的输入文件导致异常.我的命令有什么问题,因为我没有看到任何有关wordcount问题的错误相同的帖子.我是java的新手.

这可能是什么原因?

小智 19

我遇到了同样的问题.我花了一段时间才弄清楚发生了什么事.主要问题是您无法附加调试器以找出传递的值.

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

现在,如果您正在使用新框架,而您正在使用Tool类的run方法中的命令行,则args [0]是正在执行的程序的名称,在这种情况下是WordCount.

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

所以解决方案是:

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


Tho*_*lut 6

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

bin/hadoop fs -rmr jar_files/wordcount/output
Run Code Online (Sandbox Code Playgroud)

编辑
我很想念这个创作者,认为它是关于hadoop的例子jar的例子.你能在课堂上提供源代码吗?org.myorg.WordCount