public static void writeJarFromClasses(File jar, Class... types) throws IOException {
    try (JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(jar))) {
      for (Class type : types) {
        String className = type.getName();
        String classAsPath = className.replace('.', '/') + ".class";
        InputStream stream = type.getClassLoader().getResourceAsStream(classAsPath);
        byte[] bytes = IOUtils.toByteArray(stream);

        JarEntry entry = new JarEntry(classAsPath);
        entry.setTime(System.currentTimeMillis());

        jarOutputStream.putNextEntry(entry);
        jarOutputStream.write(bytes);
        jarOutputStream.closeEntry();
      }
    }
  }
Write a JAR with a class of the given name with the provided content. The className may have a
package separated by /. For example: my/package/myclass

@param className Name of the class to create
@param content Content of the created class
@param outStream Stream to write the JAR to
@throws IOException If there is a problem creating the output stream for the JAR file.
geode-junit/src/main/java/org/apache/geode/test/compiler/ClassBuilder.java