title: Start a java application from Hadoop YARN
body: <p>I'm trying to run a java application from a YARN application (in detail: from the ApplicationMaster in the YARN app). All examples I found are dealing with bash scripts that are ran.</p>
  
  <p>My problem seems to be that I distribute the JAR file wrongly to the nodes in my cluster. I specify the JAR as local resource in the YARN client.</p>
  
  <pre><code>Path jarPath2 = new Path("/hdfs/yarn1/08_PrimeCalculator.jar");
  jarPath2 = fs.makeQualified(jarPath2);
  
  FileStatus jarStat2 = null;
  try {
      jarStat2 = fs.getFileStatus(jarPath2);
      log.log(Level.INFO, "JAR path in HDFS is "+jarStat2.getPath());
  } catch (IOException e) {
      e.printStackTrace();
  }
  
  LocalResource packageResource = Records.newRecord(LocalResource.class);
  packageResource.setResource(ConverterUtils.getYarnUrlFromPath(jarPath2));
  packageResource.setSize(jarStat2.getLen());
  packageResource.setTimestamp(jarStat2.getModificationTime());
  packageResource.setType(LocalResourceType.ARCHIVE);
  packageResource.setVisibility(LocalResourceVisibility.PUBLIC);
  
  Map&lt;String, LocalResource&gt; res = new HashMap&lt;String, LocalResource&gt;();
  res.put("package", packageResource);
  </code></pre>
  
  <p>So my JAR is supposed to be distributed to the ApplicationMaster and be unpacked since I specify the ResourceType to be an ARCHIVE. On the AM I try to call a class from the JAR like this:</p>
  
  <pre><code>String command = "java -cp './package/*' de.jofre.prime.PrimeCalculator";
  </code></pre>
  
  <p>The Hadoop logs tell me when running the application: "Could not find or load main class de.jofre.prime.PrimeCalculator". The class exists at exactly the path that is shown in the error message.</p>
  
  <p>Any ideas what I am doing wrong here?</p>