Java Class Path Create getClasspathUrl(final Class aClass, final String aPath)

Here you can find the source of getClasspathUrl(final Class aClass, final String aPath)

Description

get Classpath Url

License

Open Source License

Declaration

public static URL getClasspathUrl(final Class<?> aClass,
            final String aPath) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;

public class Main {
    public static final String CLASSPATH_PREFIX = "classpath:";

    public static URL getClasspathUrl(final Class<?> aClass,
            final String aPath) throws IOException {
        if (aPath != null && aPath.startsWith(CLASSPATH_PREFIX)) {
            return getResourceUrl(aClass,
                    aPath.substring(CLASSPATH_PREFIX.length()));
        } else {//  www  .ja v  a  2s .c o m
            return null;
        }
    }

    public static URL getResourceUrl(final Class<?> aClass,
            final String aPath) throws IOException {
        final URL url = aClass.getResource(aPath);
        if (url == null) {
            throw new FileNotFoundException("Resource not found for "
                    + aClass.toString() + ": " + aPath);
        } else {
            return url;
        }
    }
}

Related

  1. getClassBasePath(URL classUrl, Class clazz)
  2. getClassPathArchiveContents(final URL resource)
  3. getClasspathResourceURL(String resourceName)
  4. getClasspathURL(final String name)
  5. getClasspathURLs(String classpath)