List of utility methods to do Jar File Find
String | getJarLocation(Class clazz) This will return the directory location of the executable jar. String executableLocation; try { URI uri = clazz.getProtectionDomain().getCodeSource().getLocation().toURI(); if (uri.toString().endsWith(".jar")) { return new File(uri.getPath()).getParentFile().getPath() + "/"; return uri.getPath(); } catch (URISyntaxException e) { ... |
URL | getJarLocation(final Class cClass) Return url of jar we are executing return cClass.getProtectionDomain().getCodeSource().getLocation();
|
Manifest | getJarManifest(File file) get Jar Manifest JarFile jar = null; try { jar = new JarFile(file); return jar.getManifest(); } finally { if (jar != null) { jar.close(); |
String | getJarOrDir(Class> mainClass) Get JAR file or directory from where the given class is loaded. String jar = mainClass.getProtectionDomain().getCodeSource().getLocation().getPath(); try { jar = URLDecoder.decode(jar, "UTF-8"); } catch (UnsupportedEncodingException e) { if (jar.startsWith("/")) { jar = jar.substring(1); return jar; |
String | getJarPath(Class> caller) get Jar Path try { URL url = caller.getProtectionDomain().getCodeSource().getLocation(); String path = URLDecoder.decode(url.getFile(), "UTF-8"); path = path.substring(1, path.lastIndexOf('/')); if (path.endsWith("target/classes")) path = path.substring(0, path.length() - "/classes".length()); path = path.replace("/", File.separator); return path + File.separator; ... |
URL | getJarPath(String pkg) get Jar Path try { Enumeration<URL> resources = Thread.currentThread().getContextClassLoader() .getResources(pkg.replace('.', '/')); while (resources.hasMoreElements()) { URL url = (URL) resources.nextElement(); return url; return null; ... |
String | getJarPathOf(Class> classObject) Returns the path to the jar-file the specified class object resides in. try { String path = URLDecoder .decode(classObject.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8"); return path; } catch (UnsupportedEncodingException e) { return ""; |