private void buildJar(File outputJarFile, List<InMemoryClassFile> compiledSourceCodes)
      throws IOException {
    assertThat(outputJarFile).doesNotExist();

    try (FileOutputStream outputStream = new FileOutputStream(outputJarFile)) {
      JarOutputStream jarOutputStream = new JarOutputStream(outputStream);
      for (InMemoryClassFile compiledSource : compiledSourceCodes) {

        String formattedName = compiledSource.getName().replace(".", "/");
        if (!formattedName.endsWith(".class")) {
          formattedName = formattedName.concat(".class");
        }

        JarEntry entry = new JarEntry(formattedName);
        entry.setTime(System.currentTimeMillis());
        jarOutputStream.putNextEntry(entry);
        jarOutputStream.write(compiledSource.getByteContent());
        jarOutputStream.closeEntry();
      }

      // Add timestamp so that the jar file itself has a new MD5 signature
      JarEntry timestampEntry = new JarEntry("timestamp");
      long now = System.currentTimeMillis();
      timestampEntry.setTime(now);
      jarOutputStream.putNextEntry(timestampEntry);
      jarOutputStream.write(Long.toString(now).getBytes());
      jarOutputStream.closeEntry();

      jarOutputStream.close();
    }
  }
This class accepts java source code in the format of .java source files or strings containing the
contents of .java source files, and compiles the given source code into a jar file specified by
the user.

<p>
Example of usage:

<pre>
`` *
&#064;Test
public void buildJarUsingStrings() {
  JarBuilder jarBuilder = new JarBuilder();
  File outputJar = new File("output.jar");

  String classInFooBarPackage = &quot;package foo.bar; public class ClassA {int n = 10;}&quot;;
  String classInDefaultPackage = &quot;public class ClassB {}&quot;;
  jarBuilder.buildJar(outputJar, classInFooBarPackage, classInDefaultPackage);
}

&#064;Test
public void buildJarUsingFiles() {
  JarBuilder jarBuilder = new JarBuilder();
  File outputJar = new File("output.jar");

  // The following two files are expected to contain valid Java source code
  File sourceFileOne = new File("ClassA.java");
  File sourceFileTwo = new File("ClassB.java");
  jarBuilder.buildJar(outputJar, sourceFileOne, sourceFileTwo);
}

</pre>
geode-junit/src/main/java/org/apache/geode/test/compiler/JarBuilder.java