FileUtils { public static List<URL> getAllClassPathUrls(ClassLoader classLoader) { try { List<URL> list = new ArrayList(); Enumeration<URL> iterator = classLoader.getResources(""); while (iterator.hasMoreElements()) { URL url = iterator.nextElement(); list.add(url); } if (classLoader instanceof URLClassLoader) { for (URL u : ((URLClassLoader) classLoader).getURLs()) { URL url = new URL("jar:" + u + "!/"); list.add(url); } } else { String classpath = System.getProperty("java.class.path"); if (classpath != null && !classpath.isEmpty()) { String[] classpathEntries = classpath.split(File.pathSeparator); for (String classpathEntry : classpathEntries) { if (classpathEntry.endsWith(".jar")) { String entryWithForwardSlashes = classpathEntry.replaceAll("\\\\", "/"); boolean startsWithSlash = entryWithForwardSlashes.startsWith("/"); URL url = new URL("jar:file:" + (startsWithSlash ? "" : "/") + entryWithForwardSlashes + "!/"); list.add(url); } } } } return list; } catch (Exception e) { throw new RuntimeException(e); } } private  FileUtils(); static final boolean isClassPath(String text); static final boolean isFilePath(String text); static final boolean isThisPath(String text); static final boolean isJsonFile(String text); static final boolean isJavaScriptFile(String text); static final boolean isYamlFile(String text); static final boolean isXmlFile(String text); static final boolean isTextFile(String text); static final boolean isCsvFile(String text); static final boolean isGraphQlFile(String text); static final boolean isFeatureFile(String text); static ScriptValue readFile(String text, ScenarioContext context); static String removePrefix(String text); static Feature parseFeatureAndCallTag(String path); static Resource toResource(String path, ScenarioContext context); static String readFileAsString(String path, ScenarioContext context); static InputStream readFileAsStream(String path, ScenarioContext context); static String toPackageQualifiedName(String path); static String toString(File file); static String toString(InputStream is); static String toPrettyString(String raw); static byte[] toBytes(InputStream is); static String toString(byte[] bytes); static byte[] toBytes(String string); static void copy(File src, File dest); static void writeToFile(File file, byte[] data); static void writeToFile(File file, String data); static InputStream toInputStream(String text); static String removeFileExtension(String path); static String replaceFileExtension(String path, String extension); static String getKarateVersion(); static void renameFileIfZeroBytes(String fileName); static String toStandardPath(String path); static String toRelativeClassPath(Path path, ClassLoader cl); static File getDirContaining(Class clazz); static Path getPathContaining(Class clazz); static File getFileRelativeTo(Class clazz, String path); static String toRelativeClassPath(Class clazz); static Path fromRelativeClassPath(String relativePath, ClassLoader cl); static Path fromRelativeClassPath(String relativePath, Path parentPath); static List<Resource> scanForFeatureFilesOnClassPath(ClassLoader cl); static List<Resource> scanForFeatureFiles(List<String> paths, ClassLoader cl); static List<Resource> scanForFeatureFiles(List<String> paths, Class clazz); static boolean isJarPath(URI uri); static Path urlToPath(URL url, String relativePath); static List<URL> getAllClassPathUrls(ClassLoader classLoader); static List<Resource> scanForFeatureFiles(boolean classpath, String searchPath, ClassLoader cl); static String getBuildDir(); static boolean isOsWindows(); static boolean isOsMacOsX(); static String getOsName(); static OsType getOsType(); static OsType getOsType(String name); static final Charset UTF8; static final byte[] EMPTY_BYTES; static final String CLASSPATH_COLON; static final String THIS_COLON; static final String FILE_COLON; static final String SRC_TEST_JAVA; static final String SRC_TEST_RESOURCES; }
@Test public void testGetAllClasspaths() { List<URL> urls = FileUtils.getAllClassPathUrls(getClass().getClassLoader()); for (URL url : urls) { logger.debug("url: {}", url); } }