private static boolean createJarArchive(File archiveFile, File[] tobeJared) {
    try {
      byte[] buffer = new byte[BUFFER_SIZE];
      // Open archive file
      FileOutputStream stream = new FileOutputStream(archiveFile);
      JarOutputStream out = new JarOutputStream(stream, new Manifest());

      for (File file : tobeJared) {
        if (file == null || !file.exists() || file.isDirectory()) {
          continue;
        }

        // Add archive entry
        JarEntry jarAdd = new JarEntry(file.getName());
        jarAdd.setTime(file.lastModified());
        out.putNextEntry(jarAdd);

        // Write file to archive
        FileInputStream in = new FileInputStream(file);
        while (true) {
          int nRead = in.read(buffer, 0, buffer.length);
          if (nRead <= 0) {
            break;
          }

          out.write(buffer, 0, nRead);
        }
        in.close();
      }
      out.close();
      stream.close();
      LOG.info("Adding classes to jar file completed");
      return true;
    } catch (Exception ex) {
      LOG.error("Error: " + ex.getMessage());
      return false;
    }
  }
Jar a list of files into a jar archive.
@param archiveFile the target jar archive
@param tobeJared   a list of files to be jared
@return true if a jar archive is build, false otherwise
hbase-common/src/test/java/org/apache/hadoop/hbase/util/ClassLoaderTestHelper.java