List of utility methods to do ClassPath
Set | findClasspathsByLoader(ClassLoader loader) find Classpaths By Loader Set<URL> urls = new HashSet<URL>(); if (loader instanceof URLClassLoader) { URLClassLoader urlLoader = (URLClassLoader) loader; urls.addAll(Arrays.asList(urlLoader.getURLs())); } else { Enumeration<URL> urlEnum; try { urlEnum = loader.getResources(""); ... |
Enumeration | findClassPathsToEn() find Class Paths To En List<URL> urls = findClassPaths(); final Iterator<URL> iterator = urls.iterator(); return new Enumeration<URL>() { @Override public boolean hasMoreElements() { return iterator.hasNext(); @Override ... |
String | findDirectoryFromClasspath(Class> cls, String file) Determine a directory's real path from the classpath. URL rootMarker = cls.getResource(file); String markerPath = rootMarker.getPath(); File markerFile = new File(markerPath); return markerFile.getParentFile().getAbsolutePath() + "/"; |
URL | findResourceOnClasspath(String resourceName) Looks for a resource on the classpath with the given name final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); return Optional.ofNullable(classLoader.getResource(resourceName)) .orElseThrow(() -> new IllegalArgumentException("Resource not found with name: " + resourceName)); |
String | getAvailableClassPathInfo(final ClassLoader classLoader) get Available Class Path Info if (!(classLoader instanceof URLClassLoader)) { return "-"; final URLClassLoader cl = (URLClassLoader) classLoader; return Arrays.toString(cl.getURLs()); |
URL[] | getBootstrapClassPath() get Bootstrap Class Path return getBootstrapURLs();
|
ClassLoader | getDriverClassLoader(String driverClasspath) Provides a ClassLoader suitable for loading SQL driver class. if (driverClasspath == null || driverClasspath.length() == 0) { return Thread.currentThread().getContextClassLoader(); } else { String pathSeparator = System.getProperty("path.separator"); String[] elements = driverClasspath.split(pathSeparator); URL[] urls = new URL[elements.length]; for (int i = 0; i < elements.length; i++) { urls[i] = new URL("file", "", elements[i].trim()); ... |
File | getFileFromClasspath(final String fileName) Load the resource either using current class loader or using parent class loader File file = null; URL url = Thread.currentThread().getClass().getResource(fileName); if (url != null) { file = new File(url.getFile()); } else { url = Thread.currentThread().getContextClassLoader().getResource(fileName); if (url != null) { file = new File(url.getFile()); ... |
File | getFileFromClasspath(String fileName) get File From Classpath URL url = Thread.currentThread().getContextClassLoader().getResource(fileName); if (url == null) return null; File file = null; try { file = new File(url.toURI()); } catch (URISyntaxException e) { file = new File(url.getPath()); ... |
String | getFileFromClasspath(String name) get File From Classpath URL url = ClassLoader.getSystemResource(name); if (url == null) { throw new IllegalArgumentException("Could not find " + name); return url.getPath(); |