【问题标题】:ClassNotFoundException while running MissingPokerCards on ec2 Instance在 ec2 实例上运行 MissingPokerCards 时出现 ClassNotFoundException
【发布时间】:2020-03-08 05:26:55
【问题描述】:

当我尝试运行 jar 文件时出现以下错误 -

        Exception in thread "main" java.lang.ClassNotFoundException: finalPoker.MissingPokerCards
                at java.net.URLClassLoader$1.run(URLClassLoader.java:360)
                at java.net.URLClassLoader$1.run(URLClassLoader.java:349)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.net.URLClassLoader.findClass(URLClassLoader.java:348)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:430)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
                at java.lang.Class.forName0(Native Method)
                at java.lang.Class.forName(Class.java:278)
                at org.apache.hadoop.util.RunJar.main(RunJar.java:153)

以下代码是我的 MissingPokerCards 程序,它将计算 52 张牌中丢失的牌数。

    package MissingPokerCards;
    import java.io.IOException;
    import java.util.ArrayList;

    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.Path;
    import org.apache.hadoop.io.IntWritable;
    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.Reducer;
    import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
    import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

    public class PokerCardsProgramme {
            //Mapper function
          //Reduce funtion
          //Main function
     public static void main(String[] args) throws Exception {
        Configuration config = new Configuration();
        Job job = new Job(config, "Search for list of missing Cards");
        job.setJarByClass(PokerCardsProgramme.class);
        job.setMapperClass(mapper.class);
        job.setReducerClass(reducer.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        job.waitForCompletion(true);
       }
    }

使用 -javac -classpath /home/ec2-user/hadoop_home/hadoop-1.2.1/hadoop-core-1.2.1.jar PokerCardsProgramme.java 编译代码

Jar 是使用以下命令创建的 - jar cvf MissingPokerCards.jar PokerCardsProgramme*.class

Jar 文件使用 - hadoop jar MissingPokerCards.jar MissingPokerCards.PokerCardsProgramme \input\inputcards.txt 输出

我的 Hadoop 版本是 1.2.1,java 版本是 1.7.0_241

即使我尝试使用不同版本的 Hadoop-2-7-3

hadoop jar /home/ec2-user/hadoop/hadoop-2.7.3/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.7.3.jar MissingPokerCards.PokerCardsProgramme inputcards.txt /output

仍然面临同样的问题。我想我缺少与 PokerCards 函数相关的 jar 文件。

谁能帮我解决这个问题。我是否使用正确的命令来编译和运行程序,否则有什么方法可以在 ec2 实例上执行 MissingPokerCards 程序。 我可以在 eclipse 中运行相同的代码,但是当我尝试在 ec2 上执行时,它显示了这个问题。

【问题讨论】:

    标签: hadoop


    【解决方案1】:

    该错误与 Hadoop 或 EC2 无关。这只是一个常规的 Java 错误。如果您真的想在 AWS 中运行 Hadoop 代码,请使用 EMR,而不是 EC2 实例

    您的包裹是MissingPokerCards。错误说它是finalPoker

    你的班级是PokerCardsProgramme。你的错误是MissingPokerCards

    FWIW,如今真正编写 mapreduce 的人并不多,但您绝对应该在 Java 8 中使用 Hadoop 2 或 3,而不是在 Java 7 中使用 1.2.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-15
      • 2016-08-05
      • 1970-01-01
      • 2020-04-10
      • 2014-07-21
      • 1970-01-01
      • 2015-03-19
      • 2011-01-13
      相关资源
      最近更新 更多