public static void addJarFilesToJar(File targetJar, String libPrefix, File... srcJars)
    throws Exception {
    FileOutputStream stream = new FileOutputStream(targetJar);
    JarOutputStream out = new JarOutputStream(stream, new Manifest());
    byte[] buffer = new byte[BUFFER_SIZE];

    for (File jarFile : srcJars) {
      // Add archive entry
      JarEntry jarAdd = new JarEntry(libPrefix + jarFile.getName());
      jarAdd.setTime(jarFile.lastModified());
      out.putNextEntry(jarAdd);

      // Write file to archive
      FileInputStream in = new FileInputStream(jarFile);
      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 jar file to outer jar file completed");
  }
Add a list of jar files to another jar file under a specific folder. It is used to generated
coprocessor jar files which can be loaded by the coprocessor class loader. It is for testing
usage only so we don't be so careful about stream closing in case any exception.
@param targetJar the target jar file
@param libPrefix the folder where to put inner jar files
@param srcJars   the source inner jar files to be added
@throws Exception if anything doesn't work as expected
hbase-common/src/test/java/org/apache/hadoop/hbase/util/ClassLoaderTestHelper.java