Java Resource Path Get getAbsoluteResource(String path)

Here you can find the source of getAbsoluteResource(String path)

Description

get Absolute Resource

License

Apache License

Declaration

public static URL getAbsoluteResource(String path) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.URL;

public class Main {
    private static ClassLoader[] theClassLoaders;

    public static URL getAbsoluteResource(String path) {
        return _getAbsoluteResource(path, true);
    }/*  ww  w  .j  ava2  s  . c om*/

    private static URL _getAbsoluteResource(String path, boolean recursive) {
        URL url = null;
        for (ClassLoader classLoader : theClassLoaders) {
            url = classLoader.getResource(path);
            if (url != null) {
                break;
            }
        }
        if (url == null && recursive) {
            if (path.startsWith("/")) {
                path = path.substring(1);
            } else {
                path = "/" + path;
            }
            url = _getAbsoluteResource(path, false);
        }
        return url;
    }
}

Related

  1. classToResource(String className)
  2. deserialize(Class parentOfResource, String resourcePath, Class targetClass)
  3. existsResource(String pathName)
  4. getAbsolutePathFromResource(Class reference, String resource)
  5. getAlternateResourceFile(final String resourcePath)
  6. getBasePath(Class clazz, String resource)
  7. getChildResources(String path)
  8. getClassResource(Class clazz, String resPath)