JarHelper { public String getJar(Class<?> jarClass, boolean makeJarFromFolder) { String jar = null; final CodeSource codeSource = jarClass.getProtectionDomain().getCodeSource(); if (codeSource != null) { URL location = codeSource.getLocation(); jar = sourceToJar.get(location); if (jar == null) { if ("jar".equals(location.getProtocol())) { try { location = ((JarURLConnection)location.openConnection()).getJarFileURL(); } catch (IOException e) { throw new AssertionError("Cannot resolve jar file for " + jarClass, e); } } if ("file".equals(location.getProtocol())) { jar = location.getFile(); final File dir = new File(jar); if (dir.isDirectory()) { if (!makeJarFromFolder) { throw new AssertionError("Cannot resolve jar file for " + jarClass + ". URL " + location); } try { jar = createJar("apex-", dir, false); } catch (IOException e) { throw new AssertionError("Cannot resolve jar file for " + jarClass + ". URL " + location, e); } } } else { throw new AssertionError("Cannot resolve jar file for " + jarClass + ". URL " + location); } sourceToJar.put(location, jar); logger.debug("added sourceLocation {} as {}", location, jar); } if (jar == null) { throw new AssertionError("Cannot resolve jar file for " + jarClass); } } return jar; }  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 getJar() throws Exception { final JarHelper jarHelper = new JarHelper(); assertNull("System jar is null", jarHelper.getJar(Class.class)); String jar = jarHelper.getJar(JarHelper.class); assertNotNull("JarHelper jar is not null", jar); assertSame(jar, jarHelper.getJar(JarHelper.class)); jar = jarHelper.getJar(JarHelperTest.class); assertNotNull("JarHelperTest jar is not null", jar); assertSame(jar, jarHelper.getJar(JarHelperTest.class)); }