/** * Locates a file on the file system or on the classpath. * <p> * Search order: * <ol> * <li>current working directory (for relative path) or any directory (for absolute path)</li> * <li>class path</li> * </ol> * * @param file the relative path of the file to locate * @return A URL to the file or null if not found */ public static URL locateFile(String file) { File fp; URL result = null; try { // try to find relative to current working directory first fp = new File(file); if (fp.exists()) { result = fp.toURI().toURL(); } // next try to load from context class loader if (result == null) { result = locateOnClassPath(file); } } catch (Exception e) { } return result; }
/** * Locates a file on the file system or on the classpath. * <p> * Search order: * <ol> * <li>current working directory (for relative path) or any directory (for absolute path)</li> * <li>class path</li> * </ol> * * @param file the relative path of the file to locate * @return A URL to the file or null if not found */ public static URL locateFile(String file) { File fp; URL result = null; try { // try to find relative to current working directory first fp = new File(file); if (fp.exists()) { result = fp.toURI().toURL(); } // next try to load from context class loader if (result == null) { result = locateOnClassPath(file); } } catch (Exception e) { } return result; }