title: Run MapReduce Job from a web application
body: <p>With reference to similar questions:
  <a href="https://stackoverflow.com/questions/14011279/running-a-hadoop-job-from-another-java-program">Running a Hadoop Job From another Java Program</a>
  and 
  <a href="https://stackoverflow.com/questions/9849776/calling-a-mapreduce-job-from-a-simple-java-program">Calling a mapreduce job from a simple java program</a></p>
  
  <p>I too have a mapreduce job jar file in a Hadoop remote machine, and I'm creating a web application that, with a button click event, will call out to the jar file and execute the job. This web app is running on a separate machine.</p>
  
  <p>I've tried the suggestions from both of the posts above but could not get it to work, even working on the wordcount example provided, but still encountering the error message NoClassDefFoundError. </p>
  
  <p>Is there any lines of code I'm missing?</p>
  
  <p>Below is the code i have:</p>
  
  <pre><code>public void buttonClick(ClickEvent event) {
          UserGroupInformation ugi;
          try {
              ugi = UserGroupInformation.createProxyUser("hadoopUser", UserGroupInformation.getLoginUser());
              ugi.doAs(new PrivilegedExceptionAction&lt;Object&gt;(){
                  public Object run() throws Exception {
                      runHadoopJob();
                      return null;
                  }
              });
          } catch (IOException e) {
              e.printStackTrace();
          } catch (InterruptedException e) {
              e.printStackTrace();
          }   
      }
  
  private boolean runHadoopJob(){
  try {       
              Configuration conf = new Configuration();
              conf.set("fs.default.name", "hdfs://192.168.4.248:9000");
              conf.set("mapred.job.tracker", "192.168.4.248:9001");
              Job job = new Job(conf, "WordCount");
              job.setMapperClass(TokenizerMapper.class);
              job.setReducerClass(IntSumReducer.class);
              job.setJarByClass(TokenizerMapper.class);
              job.setOutputKeyClass(Text.class);
              job.setOutputValueClass(IntWritable.class);
              FileInputFormat.addInputPath(job, new Path("/flume/events/160114/*"));
              Path out = new Path("output");
              FileSystem fs = FileSystem.get(conf);
              fs.delete(out, true);
              FileOutputFormat.setOutputPath(job, out);
              job.waitForCompletion(true);
              System.out.println("Job Finished");
          } catch (Exception e) {
              e.printStackTrace();
          }
  return true;
  }
  </code></pre>
  
  <blockquote>
    <p>Caused by: java.lang.NoClassDefFoundError: org/codehaus/jackson/map/JsonMappingException
        at org.apache.hadoop.mapreduce.Job$1.run(Job.java:513)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAs(Unknown Source)
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1149)
        at org.apache.hadoop.mapreduce.Job.connect(Job.java:511)
        at org.apache.hadoop.mapreduce.Job.submit(Job.java:499)
        at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:530)
        at com.example.hadoopclient.HDFSTable.runHadoopJob(HDFSTable.java:181)
        at com.example.hadoopclient.HDFSTable.access$0(HDFSTable.java:120)
        at com.example.hadoopclient.HDFSTable$SearchButtonClickListener.buttonClick(HDFSTable.java:116)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
        ... 36 more</p>
  </blockquote>
  
  <p>Added the following to my hadoop core-site.xml file, where <code>hadoop</code> is the usergroup my <code>hadoopUser</code> belongs to</p>
  
  <pre><code>&lt;property&gt;
             &lt;name&gt;hadoop.proxyuser.kohtianan.groups&lt;/name&gt;
             &lt;value&gt;hadoop&lt;/value&gt;
             &lt;description&gt;&lt;/description&gt;
           &lt;/property&gt;
           &lt;property&gt;
             &lt;name&gt;hadoop.proxyuser.kohtianan.hosts&lt;/name&gt;
             &lt;value&gt;*&lt;/value&gt;
             &lt;description&gt;&lt;/description&gt;
           &lt;/property&gt;
  </code></pre>