当前位置: 首页 > 知识库问答 >
问题:

线程“main”java中出现异常。lang.ClassNotFoundException:hdfs:。hdfs。倒转的

仲孙超
2023-03-14

执行命令时

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

我收到以下错误,有人能帮我修复代码吗

线程“main”java中出现异常。lang.ClassNotFoundException:hdfs:。hdfs。java反转。网URLClassLoader 1美元。在java上运行(URLClassLoader.java:366)。网URLClassLoader 1美元。在java上运行(URLClassLoader.java:355)。安全AccessController。java上的doPrivileged(本机方法)。网URLClassLoader。java上的findClass(URLClassLoader.java:354)。lang.ClassLoader。java上的loadClass(ClassLoader.java:425)。lang.ClassLoader。java上的loadClass(ClassLoader.java:358)。lang.Class。java上的forName0(本机方法)。lang.Class。org上的forName(Class.java:270)。阿帕奇。hadoop。util。RunJar。main(RunJar.java:205)

我尝试了所有先决条件,但仍然面临问题。在此处输入代码

下面是代码:

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);
    }
}

共有2个答案

闾丘晨
2023-03-14

hadoop命令应该知道要执行哪个类,哪个在jar参数之后直接传递:

用法:hadoop jar

所以你应该运行jar作为:

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

作业配置看起来不错。不要对作业进行任何更改。setJarbyClass:请参阅类作业

司徒云
2023-03-14

您需要在hadoop jar命令中传递Main类,如文档中所述。

您的命令

hadoop jar /home/edureka/Desktop/invertedindex.jarhdfs:/hdfs/倒置hdfs:/hdfs/无脊椎动物

应该是

hadoop jar /home/edureka/Desktop/invertedindex.jar无脊椎动物索引hdfs:/hdfs/倒置hdfs:/hdfs/无脊椎动物

而且

工作setJarByClass(反相器索引类);

应该是

job.setJarByClass(无脊椎动物索引);

相反。

我刚刚在这里进行了类似的讨论。

 类似资料: