@Test public void findFileOnClasspath() throws Exception { File testFile = fileUtils.createFileInTempDir("testFile"); addFileToClasspath(testFile); File resultFile = ClassPathUtilities.findFileOnClassPath("testFile"); assertNotNull(resultFile); assertEquals(testFile.getAbsolutePath(), resultFile.getAbsolutePath()); }
public static File findFileOnClassPath(final String fileName) { final String classpath = System.getProperty("java.class.path"); final String pathSeparator = System.getProperty("path.separator"); final StringTokenizer tokenizer = new StringTokenizer(classpath, pathSeparator); while (tokenizer.hasMoreTokens()) { final String pathElement = tokenizer.nextToken(); final File directoryOrJar = new File(pathElement); final File absoluteDirectoryOrJar = directoryOrJar.getAbsoluteFile(); if (absoluteDirectoryOrJar.isFile()) { final File target = new File(absoluteDirectoryOrJar.getParent(), fileName); if (target.exists()) { return target; } } else { final File target = new File(directoryOrJar, fileName); if (target.exists()) { return target; } } } return null; }
ClassPathUtilities { public static File findFileOnClassPath(final String fileName) { final String classpath = System.getProperty("java.class.path"); final String pathSeparator = System.getProperty("path.separator"); final StringTokenizer tokenizer = new StringTokenizer(classpath, pathSeparator); while (tokenizer.hasMoreTokens()) { final String pathElement = tokenizer.nextToken(); final File directoryOrJar = new File(pathElement); final File absoluteDirectoryOrJar = directoryOrJar.getAbsoluteFile(); if (absoluteDirectoryOrJar.isFile()) { final File target = new File(absoluteDirectoryOrJar.getParent(), fileName); if (target.exists()) { return target; } } else { final File target = new File(directoryOrJar, fileName); if (target.exists()) { return target; } } } return null; } }
ClassPathUtilities { public static File findFileOnClassPath(final String fileName) { final String classpath = System.getProperty("java.class.path"); final String pathSeparator = System.getProperty("path.separator"); final StringTokenizer tokenizer = new StringTokenizer(classpath, pathSeparator); while (tokenizer.hasMoreTokens()) { final String pathElement = tokenizer.nextToken(); final File directoryOrJar = new File(pathElement); final File absoluteDirectoryOrJar = directoryOrJar.getAbsoluteFile(); if (absoluteDirectoryOrJar.isFile()) { final File target = new File(absoluteDirectoryOrJar.getParent(), fileName); if (target.exists()) { return target; } } else { final File target = new File(directoryOrJar, fileName); if (target.exists()) { return target; } } } return null; } private  ClassPathUtilities(); }
ClassPathUtilities { public static File findFileOnClassPath(final String fileName) { final String classpath = System.getProperty("java.class.path"); final String pathSeparator = System.getProperty("path.separator"); final StringTokenizer tokenizer = new StringTokenizer(classpath, pathSeparator); while (tokenizer.hasMoreTokens()) { final String pathElement = tokenizer.nextToken(); final File directoryOrJar = new File(pathElement); final File absoluteDirectoryOrJar = directoryOrJar.getAbsoluteFile(); if (absoluteDirectoryOrJar.isFile()) { final File target = new File(absoluteDirectoryOrJar.getParent(), fileName); if (target.exists()) { return target; } } else { final File target = new File(directoryOrJar, fileName); if (target.exists()) { return target; } } } return null; } private  ClassPathUtilities(); static File findFileOnClassPath(final String fileName); }
ClassPathUtilities { public static File findFileOnClassPath(final String fileName) { final String classpath = System.getProperty("java.class.path"); final String pathSeparator = System.getProperty("path.separator"); final StringTokenizer tokenizer = new StringTokenizer(classpath, pathSeparator); while (tokenizer.hasMoreTokens()) { final String pathElement = tokenizer.nextToken(); final File directoryOrJar = new File(pathElement); final File absoluteDirectoryOrJar = directoryOrJar.getAbsoluteFile(); if (absoluteDirectoryOrJar.isFile()) { final File target = new File(absoluteDirectoryOrJar.getParent(), fileName); if (target.exists()) { return target; } } else { final File target = new File(directoryOrJar, fileName); if (target.exists()) { return target; } } } return null; } private  ClassPathUtilities(); static File findFileOnClassPath(final String fileName);  }