Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 运行hadoop时Classnotfound异常_Java_Hadoop - Fatal编程技术网

Java 运行hadoop时Classnotfound异常

Java 运行hadoop时Classnotfound异常,java,hadoop,Java,Hadoop,我是hadoop新手 我有一个文件Wordcount.java,它引用了hadoop.jar和stanford-parser.jar 我正在运行以下命令 javac -classpath .:hadoop-0.20.1-core.jar:stanford-parser.jar -d ep WordCount.java jar cvf ep.jar -C ep . bin/hadoop jar ep.jar WordCount gutenburg gutenburg1 执行后,我得到以下错

我是hadoop新手

我有一个文件Wordcount.java,它引用了hadoop.jar和stanford-parser.jar

我正在运行以下命令

javac -classpath .:hadoop-0.20.1-core.jar:stanford-parser.jar -d ep WordCount.java 

jar cvf ep.jar -C ep .

bin/hadoop jar ep.jar WordCount gutenburg gutenburg1
执行后,我得到以下错误:

lang.ClassNotFoundException: edu.stanford.nlp.parser.lexparser.LexicalizedParser
该类位于stanford-parser.jar中

可能的问题是什么


谢谢

我认为在调用hadoop时还需要添加standford解析器jar,而不仅仅是编译器。(如果您查看ep.jar,我想它将只有一个文件——WordCount.class)

例如


由于-libjars似乎不适合您,您可以尝试的另一个选项是将所有内容打包到一个jar中,即将代码+依赖项打包到一个jar中

在~Hadoop-0.18.0之前,必须这样做(他们在附近的某个地方修复了这个问题)

使用ant(我在eclipse中使用ant)可以设置一个构建,该构建可以解压依赖项并将它们添加到目标构建项目中。不过,您可能可以自己解决这个问题,方法是手动解压缩依赖项jar并将内容添加到jar中


即使我现在使用0.20.1,我仍然使用这个方法。它使从命令行开始作业变得更简单。

mdma在正确的轨道上,但您还需要作业驱动程序来实现该工具。

我也遇到了同样的问题。我认为程序无法识别-libjars选项的原因是,您没有通过调用GenericOptions Parser.getRemainingArgs()对其进行解析。在Hadoop 0.21.0的WordCount.java示例(在mapred/src/examples/org/apache/Hadoop/examples/中)中,可以找到这段代码,在我的程序中执行相同操作后,可以识别-libjars逗号分隔的jars:

String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length != 2) {
  System.err.println("Usage: wordcount <in> <out>");
  System.exit(2);
}

...
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
String[]otherArgs=新的GenericOptionsParser(conf,args).getRemainingArgs();
if(otherArgs.length!=2){
System.err.println(“用法:wordcount”);
系统出口(2);
}
...
addInputPath(作业,新路径(其他参数[0]);
setOutputPath(作业,新路径(其他参数[1]);

我刚刚发现,您只需编辑$HADOOP\u HOME/conf/HADOOP-env.sh并将JAR添加到HADOOP\u类路径中即可。
这可能是最简单也是最有效的。

您好,我尝试了您建议的命令,但在线程“main”java.lang.ClassNotFoundException中出现了此错误异常:-libjarsHi,我已在正确的位置用libjars更新了帖子。请再试一次!我尝试了您发布的命令,在线程“main”org.apache.hadoop.mapred.InvalidInputException中收到此错误异常:输入路径不存在:hdfs://localhost:11111/user/hadoop/-libjarsadding-类名之后的libjars仅使其成为发送到类的第一个参数,这是无用的
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length != 2) {
  System.err.println("Usage: wordcount <in> <out>");
  System.exit(2);
}

...
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));