简体   繁体   中英

ClassNotFoundException while running MissingPokerCards on ec2 Instance

I'm getting the following error when I try to run jar file -

        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)

The following code is my MissingPokerCards program which will count the number of missing cards from the deck of 52 cards.

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

Compiled code using - javac -classpath /home/ec2-user/hadoop_home/hadoop-1.2.1/hadoop-core-1.2.1.jar PokerCardsProgramme.java

Jar is created by using following command - jar cvf MissingPokerCards.jar PokerCardsProgramme*.class

Jar file is ran using - hadoop jar MissingPokerCards.jar MissingPokerCards.PokerCardsProgramme \\input\\inputcards.txt output

My Hadoop version is 1.2.1 and java version is 1.7.0_241

Even I tried using a different version of 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

Still facing the same issue. I think I am missing the PokerCards function related jar file.

Can anybody please help me with this problem. Am I using the correct command to compile and run the program or else is there any way to execute the MissingPokerCards program on ec2 instance. I am able to run the same code in eclipse but when I tried to execute on ec2 it is showing this issue.

The error has nothing to do with Hadoop or EC2. This is just a regular Java error. If you really want to run Hadoop code in AWS use EMR, not EC2 instances

Your package is MissingPokerCards . The error says it's finalPoker

Your class is PokerCardsProgramme . Your error says it's MissingPokerCards

FWIW, not many people actually write mapreduce nowadays, but you definitely should be using Hadoop 2 or 3 with Java 8, not 1.2.1 with Java 7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM