Java 在hadoop中运行程序时出错?
我在wordcount的hadoop 2.7中的程序在运行时在终端上给出错误,即使它在eclipse中没有显示任何错误 hadoop jar WordCount.jar WordCount用户/amandeph/file.txt wordcountoutput 错误如下所示:-Java 在hadoop中运行程序时出错?,java,hadoop,runtime-error,bigdata,Java,Hadoop,Runtime Error,Bigdata,我在wordcount的hadoop 2.7中的程序在运行时在终端上给出错误,即使它在eclipse中没有显示任何错误 hadoop jar WordCount.jar WordCount用户/amandeph/file.txt wordcountoutput 错误如下所示:- Exception in thread "main" java.lang.ClassNotFoundException: WordCount at java.net.URLClassLoader$1.run(UR
Exception in thread "main" java.lang.ClassNotFoundException: WordCount
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.apache.hadoop.util.RunJar.run(RunJar.java:214)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
我的字数计算程序是-
package hadoop_first;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
public class WordCount extends Configured implements Tool{
@Override
public int run(String[] args) throws Exception {
if(args.length<2){
System.out.println("Give directory properly");
return -1;
}
JobConf conf = new JobConf(WordCount.class);
conf.setJarByClass(WordCount.class);
FileInputFormat.setInputPaths(conf,new Path(args[0]));
FileOutputFormat.setOutputPath(conf,new Path(args[1]));
conf.setMapperClass(WordCountMapper.class);
conf.setReducerClass(WordReducer.class);
conf.setMapOutputKeyClass(Text.class);
conf.setMapOutputValueClass(IntWritable.class);
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
JobClient.runJob(conf);
return 0;
}
public static void main(String args[]){
try{
int exitCode=ToolRunner.run(new WordCount(),args);
System.exit(exitCode);
}
catch(Exception e){
System.out.println("Error");
}
}
}
先打包hadoop\u;
导入org.apache.hadoop.conf.Configured;
导入org.apache.hadoop.fs.Path;
导入org.apache.hadoop.io.IntWritable;
导入org.apache.hadoop.io.Text;
导入org.apache.hadoop.mapred.FileInputFormat;
导入org.apache.hadoop.mapred.FileOutputFormat;
导入org.apache.hadoop.mapred.JobClient;
导入org.apache.hadoop.mapred.JobConf;
导入org.apache.hadoop.util.Tool;
导入org.apache.hadoop.util.ToolRunner;
公共类WordCount扩展配置的实现工具{
@凌驾
公共int运行(字符串[]args)引发异常{
if(args.length通过在终端键入的命令中添加包名解决了该问题
hadoop jar WordCount.jar hadoop_first.WordCount file.txt wordcountoutput