List of utility methods to do ClassPath Get
String | getClassPath(Class> clazz) get Class Path String name = (new StringBuilder()).append('/').append(clazz.getName().replace('.', '/')).append(".class") .toString(); String osName = name.replace('/', File.separator.charAt(0)); URL resource = clazz.getResource(name); String absolutePath = (new File(resource.toURI())).getAbsolutePath(); return absolutePath.substring(0, absolutePath.indexOf(osName)); |
List | getClasspath(ClassLoader classLoader) get Classpath List<URL> implementationClassPath = new ArrayList<URL>(); ClassLoader stopAt = ClassLoader.getSystemClassLoader() == null ? null : ClassLoader.getSystemClassLoader().getParent(); for (ClassLoader cl = classLoader; cl != null && cl != stopAt; cl = cl.getParent()) { if (cl instanceof URLClassLoader) { implementationClassPath.addAll(Arrays.asList(((URLClassLoader) cl).getURLs())); return implementationClassPath; |
String | getClassPath(ClassLoader loader) get Class Path StringBuilder classPath = new StringBuilder(); if (loader instanceof URLClassLoader) { URLClassLoader urlLoader = (URLClassLoader) loader; for (URL url : urlLoader.getURLs()) { String file = url.getFile(); if (file.indexOf("junit") == -1) { classPath.append(url.toURI().getPort()); classPath.append(System.getProperty("path.separator")); ... |
String | getClasspath(ClassLoader loader) get Classpath Set<URL> jars = getClassLoaderClasspath(loader);
return buildClasspath(jars);
|
URL[] | getClassPath(File dir) get Class Path assert dir.isDirectory(); try { File[] files = dir.listFiles(); URL[] urls = new URL[files.length]; for (int i = 0; i < files.length; i++) { urls[i] = files[i].toURL(); return urls; ... |
String | getClassPath(Object obj, boolean bOnlyPath) get Class Path String path = null; if (obj != null) { String className = obj.getClass().getName(); int index = className.lastIndexOf("."); if (index >= 0) className = className.substring(index + 1, className.length()); URL url = obj.getClass().getResource(className + ".class"); if (url != null) { ... |
File | getClassPath(String packageName, String name) get Class Path String path = Thread.currentThread().getContextClassLoader().getResource("").getPath(); try { path = URLDecoder.decode(path, ENCODING); } catch (UnsupportedEncodingException e) { e.printStackTrace(); File file = new File(path + getFilePath(packageName, name)); return file; ... |
String | getClassPathAsString(ClassLoader classLoader) get Class Path As String String path = ""; try { URL[] urls = ((URLClassLoader) classLoader).getURLs(); for (int i = 0; i < urls.length; i++) { if (path != "") { path += ";"; path += urls[i].toString(); ... |
String | getClasspathDir(Class> klass) get Classpath Dir String file = klass.getName(); file = file.replace('.', '/') + ".class"; URL url = Thread.currentThread().getContextClassLoader().getResource(file); String baseDir = url.toURI().getPath(); baseDir = baseDir.substring(0, baseDir.length() - file.length() - 1); return baseDir; |
File | getClasspathFile(Class clz) Return the file that forms the classpath for the given class. String className = clz.getName(); String baseName = className.substring(className.lastIndexOf(".") + 1); URL classUrl = clz.getResource(baseName + ".class"); if (classUrl == null) return null; String classUrlStr = classUrl.toString(); if (classUrlStr.startsWith("jar:file:")) return getFileForUrl(classUrlStr); ... |