Java Jar File Find findJar(String nameRegexp)

Here you can find the source of findJar(String nameRegexp)

Description

find Jar

License

Apache License

Declaration

public static File findJar(String nameRegexp) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static File findJar(String nameRegexp) {
        List<File> jars = getFiles(System.getProperty("java.class.path"));
        for (File jar : jars) {
            if (jar.getName().matches(nameRegexp)) {
                return jar;
            }/*w  w  w . j  a  v a 2 s  . com*/
        }
        return null;
    }

    private static List<File> getFiles(String paths) {
        List<File> filesList = new ArrayList<>();
        for (final String path : paths.split(File.pathSeparator)) {
            final File file = new File(path);
            if (file.isDirectory()) {
                recurse(filesList, file);
            } else {
                filesList.add(file);
            }
        }
        return filesList;
    }

    private static void recurse(List<File> filesList, File f) {
        File list[] = f.listFiles();
        for (File file : list) {
            if (file.isDirectory()) {
                recurse(filesList, file);
            } else {
                filesList.add(file);
            }
        }
    }
}

Related

  1. findContainingJar(Class myClass, Map packagedClasses)
  2. findContainingJar(ClassLoader classLoader, String resourceName)
  3. findJar(Class klass)
  4. findJar(Class my_class)
  5. findJar(File dir)
  6. findJarContaining(Class c)
  7. findJarEntry(String entryName, JarInputStream jarFile)
  8. findJarFiles(String[] classPathLines)
  9. findJars(File folder)