Here you can find the source of runtimeResourceLocation(String src)
Parameter | Description |
---|---|
src | src file path or qualified class name. |
public static URL runtimeResourceLocation(String src)
//package com.java2s; /*//from w ww. j a v a 2 s . co m Copyright (C) 2003 EBI, GRL 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 2.1 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.net.URL; import com.mysql.jdbc.Driver; public class Main { /** * Attempts to resolve the src to a URL. * * This is useful for checking where a class or resource * file is being loaded from by the classloadeder. * <ul>e.g. src = ... * <li>org.ensembl.Example</li> * <li>org/ensembl/Example.class</li> * <li>com.mysql.jdbc.Driver</li> * </ul> * * Performs some magic to try to resolve the name if necessary, * e.g. for org.ensembl.Example "full names" like org/ensembl/Example.class * and org\ensembl\Example.class will be tried. * @param src src file path or qualified class name. * @return resolved URL or null if none found. */ public static URL runtimeResourceLocation(String src) { URL url = null; // String.replaceAll gets confused if sep == "\\" // (e.g. windows file separator) so we need to 'expand it' String[] variants = { src, src + ".class", src.replaceAll("\\.", "\\\\"), src.replaceAll("\\.", "\\\\") + ".class", src.replaceAll("\\.", "/"), src.replaceAll("\\.", "/") + ".class", }; for (int i = 0; url == null && i < variants.length; i++) url = Driver.class.getClassLoader().getResource(variants[i]); return url; } }