@Test public void testGetJarFile () { File file = JarUtils.getJarFileOfClass(String.class); System.out.println("jar file: " + file.getAbsolutePath()); assertNotNull(file); assertEquals(true, file.getAbsolutePath().endsWith("jar")); }
public static File getJarFileOfClass (Class<?> cls) { if (cls == null) { throw new NullPointerException("class cannot be null."); } String classResource = cls.getName().replace('.', '/') + ".class"; URL location = cls.getResource('/' + cls.getName().replace('.', '/') + ".class"); String jarPath = location.getPath(); return pathToFile(jarPath, classResource); }
JarUtils { public static File getJarFileOfClass (Class<?> cls) { if (cls == null) { throw new NullPointerException("class cannot be null."); } String classResource = cls.getName().replace('.', '/') + ".class"; URL location = cls.getResource('/' + cls.getName().replace('.', '/') + ".class"); String jarPath = location.getPath(); return pathToFile(jarPath, classResource); } }
JarUtils { public static File getJarFileOfClass (Class<?> cls) { if (cls == null) { throw new NullPointerException("class cannot be null."); } String classResource = cls.getName().replace('.', '/') + ".class"; URL location = cls.getResource('/' + cls.getName().replace('.', '/') + ".class"); String jarPath = location.getPath(); return pathToFile(jarPath, classResource); } protected  JarUtils(); }
JarUtils { public static File getJarFileOfClass (Class<?> cls) { if (cls == null) { throw new NullPointerException("class cannot be null."); } String classResource = cls.getName().replace('.', '/') + ".class"; URL location = cls.getResource('/' + cls.getName().replace('.', '/') + ".class"); String jarPath = location.getPath(); return pathToFile(jarPath, classResource); } protected  JarUtils(); static File getJarFileOfClass(Class<?> cls); static String getJarPath(Class<?> cls); }
JarUtils { public static File getJarFileOfClass (Class<?> cls) { if (cls == null) { throw new NullPointerException("class cannot be null."); } String classResource = cls.getName().replace('.', '/') + ".class"; URL location = cls.getResource('/' + cls.getName().replace('.', '/') + ".class"); String jarPath = location.getPath(); return pathToFile(jarPath, classResource); } protected  JarUtils(); static File getJarFileOfClass(Class<?> cls); static String getJarPath(Class<?> cls);  }