线程“main”java.lang.classnotfoundexception中的异常:hdfs:.hdfs.inverted

6l7fqoea  于 2021-05-29  发布在  Hadoop
关注(0)|答案(2)|浏览(297)

执行命令时

hadoop jar /home/edureka/Desktop/invertedindex.jar hdfs:/hdfs/inverted  hdfs:/hdfs/invertedout

我得到下面的错误
有人能帮我修改代码吗
线程“main”java.lang.classnotfoundexception中出现异常:hdfs:.hdfs.inverted at java.net.urlclassloader$1.run(urlclassloader。java:366)在java.net.urlclassloader$1.run(urlclassloader。java:355)位于java.net.urlclassloader.findclass(urlclassloader)的java.security.accesscontroller.doprivileged(本机方法)。java:354)在java.lang.classloader.loadclass(类加载器。java:425)在java.lang.classloader.loadclass(classloader。java:358)在java.lang.class.forname0(本机方法)在java.lang.class.forname(类。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);
    }
}
zbsbpyhn

zbsbpyhn1#

您需要在hadoopjar命令中传递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(invertedindex);
相反。
我刚才也有过类似的讨论。

kpbpu008

kpbpu0082#

hadoop命令应该知道在jar参数之后要执行哪个类: Usage: hadoop jar <jar> [mainClass] args... -参见手册
所以您应该运行jar作为:

hadoop jar /home/edureka/Desktop/invertedindex.jar InvertedIndex hdfs:/hdfs/inverted  hdfs:/hdfs/invertedout

作业配置看起来不错。不要更改 job.setJarbyClass :见班级作业

相关问题