JarUtils { public static JarFile toJarFile(URL jarURL) throws IOException { JarFile jarFile = null; final String jarAbsolutePath = resolveJarAbsolutePath(jarURL); if (jarAbsolutePath == null) return null; jarFile = new JarFile(jarAbsolutePath); return jarFile; }  static JarFile toJarFile(URL jarURL); @Nonnull static String resolveRelativePath(URL jarURL); @Nonnull static String resolveJarAbsolutePath(URL jarURL); @Nonnull static List<JarEntry> filter(JarFile jarFile, JarEntryFilter jarEntryFilter); static JarEntry findJarEntry(URL jarURL); static void extract(File jarSourceFile, File targetDirectory); static void extract(File jarSourceFile, File targetDirectory, JarEntryFilter jarEntryFilter); static void extract(JarFile jarFile, File targetDirectory, JarEntryFilter jarEntryFilter); static void extract(URL jarResourceURL, File targetDirectory, JarEntryFilter jarEntryFilter);  }
@Test public void testToJarFile() throws Exception { URL resourceURL = ClassLoaderUtils.getClassResource(classLoader, String.class); JarFile jarFile = JarUtils.toJarFile(resourceURL); JarFile rtJarFile = new JarFile(new File(SystemUtils.JAVA_HOME, "/lib/rt.jar")); Assert.assertNotNull(jarFile); Assert.assertEquals(rtJarFile.getName(), jarFile.getName()); }
@Test(expected = IllegalArgumentException.class) public void testToJarFileOnException() throws Exception { URL url = new URL("http: JarFile jarFile = JarUtils.toJarFile(url); }