hadoop jar /home/edureka/Desktop/invertedindex.jar hdfs:/hdfs/inverted hdfs:/hdfs/invertedout
我收到以下错误
任何人都可以帮我修复代码
线程中的异常" main" java.lang.ClassNotFoundException:hdfs:.hdfs.inverted 在java.net.URLClassLoader $ 1.run(URLClassLoader.java:366) 在java.net.URLClassLoader $ 1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) 在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) 在java.lang.Class.forName(Class.java:270) 在org.apache.hadoop.util.RunJar.main(RunJar.java:205)
我尝试了所有先决条件但仍面临问题。enter code here
以下是代码:
import java.io.IOException;
import java.util.HashMap;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.mapreduce.Reducer;
public class InvertedIndex {
public static class Map extends Mapper<LongWritable,Text,Text,Text> {
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException,InterruptedException
{
String fileName = ((FileSplit) context.getInputSplit()).getPath().getName();
String line=value.toString();
String words[]=line.split(" ");
for(String s:words){
context.write(new Text(s), new Text(fileName));
}
}
}
public static class Reduce extends
Reducer<Text, Text, Text, Text> {
@Override
public void reduce(Text key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
HashMap m=new HashMap();
int count=0;
for(Text t:values){
String str=t.toString();
if(m!=null &&m.get(str)!=null){
count=(int)m.get(str);
m.put(str, ++count);
}else{`enter code here`
m.put(str, 1);
}
}
context.write(key, new Text(m.toString()));
}
}
public static void main(String[] args) throws Exception {
Configuration conf= new Configuration();
Job job = new Job(conf,"UseCase1");
//Defining the output value class for the mapper
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
job.setJarByClass(InvertedIndex.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
//Defining the output value class for the mapper
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
Path outputPath = new Path(args[1]);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, outputPath);
//deleting the output path automatically from hdfs so that we don't have delete it explicitly
outputPath.getFileSystem(conf).delete(outputPath);
//exiting the job only if the flag value becomes false
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
答案 0 :(得分:0)
您需要在hadoop jar命令中传递Main类,如文档中所述。
你的命令
hadoop jar /home/edureka/Desktop/invertedindex.jar hdfs:/ hdfs / inverted HDFS:/ HDFS / invertedout
应该是
hadoop jar /home/edureka/Desktop/invertedindex.jar InvertedIndex hdfs:/ hdfs / inverted hdfs:/ hdfs / invertedout
另外
job.setJarByClass(InvertedIndex.class);
应该是
job.setJarByClass(倒排索引);
代替。
我刚刚进行了类似的讨论here。
答案 1 :(得分:0)
hadoop命令应该知道在jar参数后正在执行哪个类:
Usage: hadoop jar <jar> [mainClass] args...
- see manual
所以你应该运行jar as:
hadoop jar /home/edureka/Desktop/invertedindex.jar InvertedIndex hdfs:/hdfs/inverted hdfs:/hdfs/invertedout
工作配置看起来不错。不要对job.setJarbyClass
:see Class-Job