Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster
Asked Answered
D

6

16

Contents of mapred-site.xml :

<configuration>
<property>
 <name>mapreduce.framework.name</name>
 <value>yarn</value>
</property>

<property>
 <name>yarn.app.mapreduce.am.env</name>
 <value>HADOOP_MAPRED_HOME=/home/admin/hadoop-3.1.0</value>
</property>

<property>
 <name>mapreduce.map.env</name>
 <value>HADOOP_MAPRED_HOME=/home/admin/hadoop-3.1.0</value>
</property>

<property>
 <name>mapreduce.reduce.env</name>
 <value>HADOOP_MAPRED_HOME=/home/admin/hadoop-3.1.0</value>
</property>

<property> 
    <name>mapreduce.application.classpath</name>
    <value>$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*,$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*</value>
</property>

</configuration>

Though I have set yarn.app.mapreduce.am.env and other parameters; I am getting Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster error. I am trying to run map reduce program remotely where hadoop is installed on linux machine and I am running it from windows machine. Following are my configuration settings for job.

public class WordCount {
  public static void main(String[] args)
      throws IOException, ClassNotFoundException, InterruptedException {
    //
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser("admin");
    ugi.doAs(new PrivilegedExceptionAction<Void>() {

      public Void run() throws Exception {
        try {
          Configuration configuration = new Configuration();

          configuration.set("yarn.resourcemanager.address", "192.168.33.75:50001"); // see step 3
          configuration.set("mapreduce.framework.name", "yarn");
          // configuration.set("yarn.app.mapreduce.am.env",
          // "HADOOP_MAPRED_HOME=/home/admin/hadoop-3.1.0");
          // configuration.set("mapreduce.map.env", "HADOOP_MAPRED_HOME=/home/admin/hadoop-3.1.0");
          // configuration.set("mapreduce.reduce.env",
          // "HADOOP_MAPRED_HOME=/home/admin/hadoop-3.1.0");
          configuration.set("fs.defaultFS", "hdfs://192.168.33.75:54310"); // see step 2
          configuration.set("mapreduce.app-submission.cross-platform", "true");
          configuration.set("mapred.remote.os", "Linux");
          configuration.set("yarn.application.classpath",
              "$HADOOP_CONF_DIR:$HADOOP_COMMON_HOME/*:$HADOOP_COMMON_HOME/lib/*:"
                  + "$HADOOP_HDFS_HOME/*:$HADOOP_HDFS_HOME/lib/*:"
                  + "$HADOOP_YARN_HOME/*:$HADOOP_YARN_HOME/lib/*:"
                  + "$HADOOP_MAPRED_HOME/*:$HADOOP_MAPRED_HOME/lib/*");

          Job job = Job.getInstance(configuration);

          job.setJarByClass(WordCount.class); // use this when uploaded the Jar to the server and
                                              // running the job directly and locally on the server
          job.setOutputKeyClass(Text.class);
          job.setOutputValueClass(IntWritable.class);
          job.setMapperClass(MapForWordCount.class);
          job.setReducerClass(ReduceForWordCount.class);

          Path input = new Path("/user/admin/wordCountInput.txt");
          Path output = new Path("/user/admin/output");
          FileInputFormat.addInputPath(job, input);
          FileOutputFormat.setOutputPath(job, output);
          System.exit(job.waitForCompletion(true) ? 0 : 1);
        } catch (Exception e) {
          e.printStackTrace();
        }
        return null;
      }

    });


  }

Please help me. I am stuck on this problem from last 6 days. Thanks a lot in advance. Hadoop version : 3.1.0

Dostie answered 19/6, 2018 at 11:42 Comment(1)
In a situation like this, it can be handy to symlink /home/admin/hadoop-3.1.0 to /home/admin/hadoop ... when you upgrade hadoop, you change the symlink, but do not have to change the version number in all of your config files.Wizen
D
5

I added following property in yarn-site.xml

<property>
  <name>yarn.application.classpath</name>
  <value> $HADOOP_CONF_DIR,$HADOOP_COMMON_HOME/share/hadoop/common/*,$HADOOP_COMMON_HOME/share/hadoop/common/lib/*,$HADOOP_HDFS_HOME/share/hadoop/hdfs/*,$HADOOP_HDFS_HOME/share/hadoop/hdfs/lib/*,$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*,$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*,
    $HADOOP_YARN_HOME/share/hadoop/yarn/*,$HADOOP_YARN_HOME/share/hadoop/yarn/lib/* 
  </value>
</property>

And did same changes in my map reduce program.

  configuration.set("yarn.application.classpath",
              "{{HADOOP_CONF_DIR}},{{HADOOP_COMMON_HOME}}/share/hadoop/common/*,{{HADOOP_COMMON_HOME}}/share/hadoop/common/lib/*,"
                  + " {{HADOOP_HDFS_HOME}}/share/hadoop/hdfs/*,{{HADOOP_HDFS_HOME}}/share/hadoop/hdfs/lib/*,"
                  + "{{HADOOP_MAPRED_HOME}}/share/hadoop/mapreduce/*,{{HADOOP_MAPRED_HOME}}/share/hadoop/mapreduce/lib/*,"
                  + "{{HADOOP_YARN_HOME}}/share/hadoop/yarn/*,{{HADOOP_YARN_HOME}}/share/hadoop/yarn/lib/*");

My program is running smoothly now. Feel free to ask me details.

Dostie answered 21/6, 2018 at 12:56 Comment(0)
C
20

Just edit the mapred-site.xml file :

Add following properties:

  1. <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property>

  2. <property> <name>yarn.app.mapreduce.am.env</name> <value>HADOOP_MAPRED_HOME=/Users/adityaatri/Applications/hadoop-3.1.3</value> </property>

  3. <property> <name>mapreduce.map.env</name> <value>HADOOP_MAPRED_HOME=/Users/adityaatri/Applications/hadoop-3.1.3</value> </property>

  4. <property> <name>mapreduce.reduce.env</name> <value>HADOOP_MAPRED_HOME=/Users/adityaatri/Applications/hadoop-3.1.3</value> </property>

Now for all the above 4 properties, replace the path /Users/adityaatri/Applications/hadoop-3.1.3 with your Hadoop Home Address.

Now add the 5th property :

  1. <property> <name>mapreduce.application.classpath</name> <value></value> </property>

The <value> element must be filled with content after executing below commands in your terminal :

  1. export HADOOP_CLASSPATH=$(hadoop classpath)

  2. echo $HADOOP_CLASSPATH

The output from my terminal :

/Users/adityaatri/Applications/hadoop-3.1.3/etc/hadoop:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/common/lib/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/common/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/hdfs:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/hdfs/lib/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/hdfs/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/mapreduce/lib/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/mapreduce/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/yarn:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/yarn/lib/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/yarn/*

Copy this content inside the <value> element of the 5th property.

Now you will not get any error. :)

Cornute answered 12/4, 2020 at 12:15 Comment(0)
C
16

I had the same problem and resolved by adding this in mapred-site.xml (so edit your mapreduce.application.classpath property)

<property> 
    <name>mapreduce.application.classpath</name>
    <value>$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*,$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*,$HADOOP_MAPRED_HOME/share/hadoop/common/*,$HADOOP_MAPRED_HOME/share/hadoop/common/lib/*,$HADOOP_MAPRED_HOME/share/hadoop/yarn/*,$HADOOP_MAPRED_HOME/share/hadoop/yarn/lib/*,$HADOOP_MAPRED_HOME/share/hadoop/hdfs/*,$HADOOP_MAPRED_HOME/share/hadoop/hdfs/lib/*</value>
</property>
Complicacy answered 21/6, 2018 at 9:2 Comment(1)
Make sure you have both share/hadoop/X/* and share/hadoop/X/lib/*. I encountered the same problem and the issue turned out be having share/hadoop/yarn/* but missing share/hadoop/yarn/lib/*!Janellejanene
D
5

I added following property in yarn-site.xml

<property>
  <name>yarn.application.classpath</name>
  <value> $HADOOP_CONF_DIR,$HADOOP_COMMON_HOME/share/hadoop/common/*,$HADOOP_COMMON_HOME/share/hadoop/common/lib/*,$HADOOP_HDFS_HOME/share/hadoop/hdfs/*,$HADOOP_HDFS_HOME/share/hadoop/hdfs/lib/*,$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*,$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*,
    $HADOOP_YARN_HOME/share/hadoop/yarn/*,$HADOOP_YARN_HOME/share/hadoop/yarn/lib/* 
  </value>
</property>

And did same changes in my map reduce program.

  configuration.set("yarn.application.classpath",
              "{{HADOOP_CONF_DIR}},{{HADOOP_COMMON_HOME}}/share/hadoop/common/*,{{HADOOP_COMMON_HOME}}/share/hadoop/common/lib/*,"
                  + " {{HADOOP_HDFS_HOME}}/share/hadoop/hdfs/*,{{HADOOP_HDFS_HOME}}/share/hadoop/hdfs/lib/*,"
                  + "{{HADOOP_MAPRED_HOME}}/share/hadoop/mapreduce/*,{{HADOOP_MAPRED_HOME}}/share/hadoop/mapreduce/lib/*,"
                  + "{{HADOOP_YARN_HOME}}/share/hadoop/yarn/*,{{HADOOP_YARN_HOME}}/share/hadoop/yarn/lib/*");

My program is running smoothly now. Feel free to ask me details.

Dostie answered 21/6, 2018 at 12:56 Comment(0)
C
1

Just add the following to yarn-site.xml so the environment variables are passed down. I had the same issue and this resolved it. I am running Hadoop 3.3.6.

<property>
    <name>yarn.nodemanager.env-whitelist</name>
    <value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_HOME,PATH,LANG,TZ,HADOOP_MAPRED_HOME
    </value>
</property>
Civics answered 28/7, 2023 at 22:4 Comment(1)
The accepted answer is using relative paths that are not needed. It is also suggesting to set paths in the code, again not needed. The cleaner solution is o just pass all the environment variables to any application via the system configuration files. Less changes :-)Civics
W
0

The issue is that Your Resource Manager(yarn) is not able to load Hadoop Libraries(jars). I solved this by updating the configurations. Added this to yarn-site.xml :

<property>
<name>yarn.application.classpath</name>
<value>C:/hadoop-2.8.0/share/hadoop/mapreduce/*,C:/hadoop-2.8.0/share/hadoop/mapreduce/lib/*,C:/Hadoop-2.8.0/share/hadoop/common/*,C:/Hadoop-2.8.0/share/hadoop/common/lib/*,
    C:/hadoop-2.8.0/share/hadoop/hdfs/*,C:/hadoop-2.8.0/share/hadoop/hdfs/lib/*,C:/hadoop-2.8.0/share/hadoop/yarn/*,C:/hadoop-2.8.0/share/hadoop/yarn/lib/*</value>
</property>

Please note that the paths used here can be relative according to your system.

Watusi answered 1/12, 2018 at 15:53 Comment(0)
D
0

I add the mapreduce.application.classpath in mapred.xml, but it sitll doesn't work. Then i download the core-site.xml, mapred-site.xml and yarn-site.xml files from my linux server, then put these files into the resources path in you IDEA, then it works!

Desta answered 24/3, 2022 at 13:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.