Here you can find the source of getResource(final String resourceName, final Class> caller)
public static URL getResource(final String resourceName, final Class<?> caller)
//package com.java2s; import java.net.URL; public class Main { public static URL getResource(final String resourceName, final Class<?> caller) { final String resource; if (resourceName.startsWith("/")) { resource = resourceName.substring(1); } else {//from ww w . ja v a 2s.c om final Package callerPackage = caller.getPackage(); if (callerPackage != null) { resource = callerPackage.getName().replace('.', '/') + '/' + resourceName; } else { resource = resourceName; } } final ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader(); if (threadClassLoader != null) { final URL url = threadClassLoader.getResource(resource); if (url != null) { return url; } } final ClassLoader classLoader = caller.getClassLoader(); if (classLoader != null) { final URL url = classLoader.getResource(resource); if (url != null) { return url; } } return ClassLoader.getSystemResource(resource); } }