public static void jarDir(File dir, String relativePath, ZipOutputStream zos) throws IOException {
    Preconditions.checkNotNull(relativePath, "relativePath");
    Preconditions.checkNotNull(zos, "zos");

    // by JAR spec, if there is a manifest, it must be the first entry in the
    // ZIP.
    File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
    ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
    if (!manifestFile.exists()) {
      zos.putNextEntry(manifestEntry);
      new Manifest().write(new BufferedOutputStream(zos));
      zos.closeEntry();
    } else {
      copyToZipStream(manifestFile, manifestEntry, zos);
    }
    zos.closeEntry();
    zipDir(dir, relativePath, zos, true);
    zos.close();
  }
Finds the Jar for a class. If the class is in a directory in the classpath, it creates a Jar on
the fly with the contents of the directory and returns the path to that Jar. If a Jar is created,
it is created in the system temporary directory. This file was forked from
hadoop/common/branches/branch-2@1377176.
hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/JarFinder.java