Java Utililty Methods Jar File Find

List of utility methods to do Jar File Find

Description

The list of methods to do Jar File Find are organized into topic(s).

Method

FilefindJar(File dir)
find Jar
if (dir == null || !dir.isDirectory()) {
    return null;
for (File file : dir.listFiles()) {
    if (file.isDirectory()) {
        File f = findJar(file);
        if (f != null) {
            return f;
...
FilefindJar(String nameRegexp)
find Jar
List<File> jars = getFiles(System.getProperty("java.class.path"));
for (File jar : jars) {
    if (jar.getName().matches(nameRegexp)) {
        return jar;
return null;
JarFilefindJarContaining(Class c)
find Jar Containing
URLClassLoader cl = (URLClassLoader) c.getClassLoader();
String cn = c.getCanonicalName();
URL url = cl.findResource(cn.replace(".", "/") + ".class");
String s = url.getFile().substring(url.getProtocol().length() + 2);
String jar = s.substring(0, s.lastIndexOf("!"));
return new JarFile(jar);
JarEntryfindJarEntry(String entryName, JarInputStream jarFile)
find Jar Entry
JarEntry jarEntry = jarFile.getNextJarEntry();
while (jarEntry != null) {
    if (jarEntry.getName().equals(entryName)) {
        break;
    } else {
        jarEntry = jarFile.getNextJarEntry();
return jarEntry;
String[]findJarFiles(String[] classPathLines)
find Jar Files
Set<String> jars = new HashSet<String>();
for (String locationsLine : classPathLines) {
    if (locationsLine == null)
        continue;
    for (String CPentry : locationsLine.split(":")) {
        if (CPentry.endsWith(".jar"))
            jars.add(new File(CPentry).getAbsoluteFile().toString());
return jars.toArray(new String[0]);
ListfindJars(File folder)
Returns all JAR files in folder.
List<File> result = new ArrayList<File>();
File[] plugins = folder.listFiles();
if (null != plugins) {
    for (File f : plugins) {
        if (f.getName().endsWith(".jar")) {
            result.add(f);
System.out.println("JARS found: " + result.toString());
return result;
File[]findJars(File libDir)
find Jars
File[] jarFiles = new File[0];
if (libDir.isDirectory()) {
    jarFiles = libDir.listFiles(JAR_FILES_FILTER);
return jarFiles;
StringfindJarsDir(String sparkHome, String scalaVersion, boolean failIfNotFound)
Find the location of the Spark jars dir, depending on whether we're looking at a build or a distribution directory.
File libdir;
if (new File(sparkHome, "RELEASE").isFile()) {
    libdir = new File(sparkHome, "jars");
    checkState(!failIfNotFound || libdir.isDirectory(), "Library directory '%s' does not exist.",
            libdir.getAbsolutePath());
} else {
    libdir = new File(sparkHome, String.format("assembly/target/scala-%s/jars", scalaVersion));
    if (!libdir.isDirectory()) {
...
URL[]findJarsFromDirectory(File targetDirectory)
find Jars From Directory
File[] files = targetDirectory.listFiles();
URL[] urls = new URL[files.length];
for (int i = 0; i < files.length; i++) {
    if (files[i].getName().endsWith(".jar")) {
        try {
            urls[i] = files[i].toURI().toURL();
        } catch (MalformedURLException e) {
            e.printStackTrace();
...
SetfindJarsNamesInPath(String path)
find Jars Names In Path
File[] jarArray = new File(path).listFiles(new FilenameFilter() {
    @Override
    public boolean accept(File dir, String name) {
        return name.endsWith(".jar");
});
HashSet<String> jarNames = new HashSet<>();
for (File jar : jarArray) {
...