JarHelper { public static String createJar(String prefix, File dir, boolean deleteOnExit) throws IOException { if (!dir.exists() || !dir.isDirectory()) { throw new IllegalArgumentException(String.format("dir %s must be an existing directory.", dir)); } File temp = File.createTempFile(prefix, ".jar"); if (deleteOnExit) { temp.deleteOnExit(); } new JarCreator(temp).createJar(dir); return temp.getAbsolutePath(); }  static String createJar(String prefix, File dir, boolean deleteOnExit); String getJar(Class<?> jarClass, boolean makeJarFromFolder); String getJar(Class<?> jarClass); Set<String> getJars(Class<?> jarClass, boolean makeJarFromFolder, boolean addJarDependencies); Set<String> getJars(Class<?> jarClass); void getDependentJarsFromManifest(JarFile jarFile, Set<String> set);  }
@Test public void createJar() throws Exception { JarFile jar = new JarFile(JarHelper.createJar("apex", folder.getRoot(), true)); logger.debug("Created jar {} with MANIFEST only.", jar.getName()); assertNotNull("MANIFEST exists", jar.getManifest()); assertNull(jar.getEntry(file)); assertNull(jar.getEntry(dir)); jar.close(); Files.write(folder.newFile(file).toPath(), data); folder.newFolder(dir); jar = new JarFile(JarHelper.createJar("apex", folder.getRoot(), true)); logger.debug("Created jar {} with a file and a directory.", jar.getName()); assertNotNull("MANIFEST exists", jar.getManifest()); ZipEntry entry = jar.getEntry(file); assertNotNull(entry); assertFalse(entry.isDirectory()); byte[] data = new byte[JarHelperTest.data.length]; jar.getInputStream(entry).read(data); assertArrayEquals(data, JarHelperTest.data); assertTrue(jar.getEntry(dir).isDirectory()); jar.close(); folder.newFolder(META); Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, version); manifest.write(new FileOutputStream(folder.newFile(JarFile.MANIFEST_NAME))); jar = new JarFile(JarHelper.createJar(JarHelperTest.class.getSimpleName(), folder.getRoot(), true)); logger.debug("Created jar {} with a file, a directory and a MANIFEST.", jar.getName()); assertEquals("MANIFEST version", jar.getManifest().getMainAttributes().getValue(Attributes.Name.MANIFEST_VERSION), version); entry = jar.getEntry(file); assertNotNull(entry); assertFalse(entry.isDirectory()); jar.getInputStream(entry).read(data); assertArrayEquals(data, JarHelperTest.data); assertTrue(jar.getEntry(dir).isDirectory()); jar.close(); }