List of utility methods to do ClassPath
File | getFileFromClasspathResource(String resource) get File From Classpath Resource return new File(findBasePathFromClasspathResource(resource), resource); |
String | getFilePathFromClasspath(String filename) Gets the absolute path of a file with given filename, searching classpath. java.net.URL url = ClassLoader.getSystemClassLoader().getResource(filename); if (null != url && "file".equals(url.getProtocol())) { return url.getPath(); return null; |
String | getFullPath(String classPath) get Full Path String fileClassPath = classPath; if (fileClassPath == null) { fileClassPath = ""; ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource(fileClassPath); if (url != null) { return url.getFile(); ... |
InputStream | getInputStreamFromClasspathFile(final String fileName) get Input Stream From Classpath File return new FileInputStream(getFileFromClasspath(fileName)); |
URL | getResourceFromClasspath(final String fileName) get Resource From Classpath return Thread.currentThread().getContextClassLoader().getResource(fileName);
|
InputStream | getStreamFromClassPath(String source) get Stream From Class Path URL retURL = getURLFromClassPath(source); if (retURL == null) return null; return retURL.openStream(); |
URL[] | getSystemClassPath() get System Class Path return getAppClassLoader().getURLs();
|
URL[] | getSystemClasspathEntries() get System Classpath Entries String[] paths = System.getProperty("java.class.path").split(File.pathSeparator); URL[] urls = new URL[paths.length]; for (int i = 0; i < paths.length; i++) { urls[i] = new File(paths[i]).toURI().toURL(); return urls; |
boolean | isInClassPath(String location) Returns true if the specified location is in the JVM classpath. return isInClassPath(new File(location).toURI().toURL()); |
Set | loadDirectoryFromClasspath(String path) load Directory From Classpath ClassLoader cl = getContextClassLoader(); Enumeration<URL> urls = cl.getResources(path); Set<String> children = new HashSet<>(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); URI uri = null; if ("jar".equals(url.getProtocol())) { uri = new URI(url.toString().replaceAll("^jar:(.+)!/.*$", "$1")); ... |