Here you can find the source of findResource(Class> clazz)
public static URL findResource(Class<?> clazz)
//package com.java2s; /*/* w ww. ja va 2 s . c om*/ Copyright (C) 2012 Jason Gardner This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, see <http://www.gnu.org/licenses/>. "XSD2Whatever" - builds upon and incorprates many pieces of the GraniteDS project and, therefore, assumes the same licensing model. www.graniteds.org */ import java.net.URL; public class Main { public static URL findResource(Class<?> clazz) { if (clazz.isArray()) { clazz = clazz.getComponentType(); } if (clazz.isPrimitive()) { return null; } ClassLoader loader = (clazz.getClassLoader() != null ? clazz.getClassLoader() : ClassLoader.getSystemClassLoader()); return loader.getResource(clazz.getName().replace('.', '/').concat(".class")); } }