private static void exploreJar(URL location, List<URL> urls, File tmpDir,
      boolean includeWarLibs) throws IOException, MalformedURLException,
      URISyntaxException {

    JarInputStream jar = new JarInputStream(location.openStream());
    JarEntry entry = null;

    while ((entry = jar.getNextJarEntry()) != null) {

      String name = entry.getName();

      /**
       * The bulk of the JARs we care about are already in the WEB-INF/lib
       * directory of the parent WAR. However, we've put a few additional
       * dependencies in META-INF/bootstrap-lib to help with running the
       * embedded webapp.
       */
      if ((name.startsWith("META-INF/bootstrap-lib") || (includeWarLibs && name.startsWith("WEB-INF/lib")))
          && name.endsWith(".jar")) {

        name = name.replace("META-INF/", "");

        File outputJar = new File(tmpDir, name);
        outputJar.deleteOnExit();

        outputJar.getParentFile().mkdirs();
        OutputStream out = new BufferedOutputStream(new FileOutputStream(
            outputJar));
        byte[] buffer = new byte[1024];
        while (true) {
          int rc = jar.read(buffer);
          if (rc == -1)
            break;
          out.write(buffer, 0, rc);
        }
        out.close();
        urls.add(outputJar.toURI().toURL());
      }
    }
    jar.close();
  }