Java Utililty Methods ClassPath

List of utility methods to do ClassPath

Description

The list of methods to do ClassPath are organized into topic(s).

Method

FilegetFileFromClasspathResource(String resource)
get File From Classpath Resource
return new File(findBasePathFromClasspathResource(resource), resource);
StringgetFilePathFromClasspath(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;
StringgetFullPath(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();
...
InputStreamgetInputStreamFromClasspathFile(final String fileName)
get Input Stream From Classpath File
return new FileInputStream(getFileFromClasspath(fileName));
URLgetResourceFromClasspath(final String fileName)
get Resource From Classpath
return Thread.currentThread().getContextClassLoader().getResource(fileName);
InputStreamgetStreamFromClassPath(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;
booleanisInClassPath(String location)
Returns true if the specified location is in the JVM classpath.
return isInClassPath(new File(location).toURI().toURL());
SetloadDirectoryFromClasspath(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")); 
...