Java 无法从Hadoop中的空字符串创建路径

Java 无法从Hadoop中的空字符串创建路径,java,hadoop,mapreduce,toolrunner,Java,Hadoop,Mapreduce,Toolrunner,我正在使用ToolRunner来运行我的工作 public class ToolRunner1 extends Configured implements Tool { public static void main(String[] args) throws Exception { System.out.println("In main"); int exitCode = ToolRunner.run(new ToolRunner1(), args); System.exit(exitCo

我正在使用ToolRunner来运行我的工作

public class ToolRunner1 extends Configured implements Tool {
public static void main(String[] args) throws Exception {
System.out.println("In main");
 int exitCode = ToolRunner.run(new ToolRunner1(), args);
 System.exit(exitCode);
 }

 @Override
public int run(String [] args) throws Exception {

Configuration conf = getConf();
FileSystem fs = FileSystem.get(conf);    
Path p1 = new Path(conf.get("input1")); //Receving a NULL Value
Path p2 = new Path(conf.get("input2")); //Receving a NULL Value
Path p3 = new Path(conf.get("output")); //Receving a NULL Value
if (fs.exists(p3)) {
 fs.delete(p3, true);
}
Job job = new Job(conf, "ToolRunner");
job.setJarByClass(ToolRunner1.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);

job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);

job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);

FileInputFormat.addInputPath(job,p1);
FileOutputFormat.setOutputPath(job, p3);

boolean success = job.waitForCompletion(true);
return(success ? 0 : 1);
 }

}
我运行的命令:

hadoop jar toolru.jar -D input1=/home/sreeveni/myfiles/tab -D input2=/home/sreeveni/myfiles/tab -D output =/home/sreeveni/myfiles/OUT/Toll
但是

Exception in thread "main" java.lang.IllegalArgumentException: Can not create a Path from a null string
我做错什么了吗? 请建议

已编辑 按照克里斯的建议,我更新了代码。并且可以通过EclipseIDE正常工作 当我将jar移植到集群时,它会给出相同的错误

hadoop jar toolru.jar tool.ToolRunner1 -D input1=/home/sreeveni/myfiles/tab -D input2=/home/sreeveni/myfiles/tab -D output =/home/sreeveni/myfiles/OUT/Toll
我想你想要:

Configuration conf = getConf();
而不是

Configuration conf = new Configuration();
试试这个, 不要使用-D选项,而是使用命令行参数,然后使用字符串[]args来创建路径(新路径(args[0]),等等)

这可能会为您提供关于-D选项用法的线索(对于用户定义的键值对,-D选项是否可用,或者该选项仅用于添加配置(core-*.xml)级别的更改)


您在eclipse中的执行情况如何?能否给出运行期间应用的参数(运行配置)?

是。我编辑了我的代码,现在它可以在独立模式下完美运行(在EclipseIDE中使用hadoop库)。但当我尝试在8节点集群中再次运行同一个jar时,显示出相同的错误。它再次在所有conf.get中接收到空值。在集群中运行时,我使用此命令,它在集群中不起作用,一旦我将mainclass与该命令一起删除,它就可以正常工作。如果我还需要包含类名呢?我想hadoop中不存在OUT目录。你能告诉我这个命令返回什么hadoop fs-ls/home/sreeveni/myfiles/OUT/@PradyumnaMohapatra:现在我的问题是“在集群中运行时,我使用这个命令,它在集群中不起作用,一旦我删除了我的main类和这个命令,它就可以正常工作了。如果我还需要包含类名怎么办?”使用ToolRunner是编写我的问题所在的错误代码的更好方法“在集群中运行时,我使用这个命令,它在集群中不起作用,一旦我将main类与该命令一起删除,它就可以正常工作。如果我还需要包含类名呢?问这个问题的原因是,使用参数进行测试是为了确保其他东西与您的配置相匹配。但看起来toolrunner无法正确解析命令行。尝试只给出两个值:input1和output。但是我可以在没有类名的情况下运行它们