Java Jar File Find getJarFile(Class clazz)

Here you can find the source of getJarFile(Class clazz)

Description

get Jar File

License

LGPL

Declaration

public static String getJarFile(Class clazz) 

Method Source Code

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

import java.net.URL;

public class Main {
    public static String getJarFile(Class clazz) {
        String result = null;/*w  w w .j  a va 2 s  . com*/
        if (clazz != null) {
            String me = clazz.getName().replace(".", "/") + ".class";
            URL dirURL = clazz.getClassLoader().getResource(me);

            if (dirURL.getProtocol().equals("jar")) {
                result = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!"));
            }
        }
        return result;
    }
}

Related

  1. findJarsDir(String sparkHome, String scalaVersion, boolean failIfNotFound)
  2. findJarsFromDirectory(File targetDirectory)
  3. findJarsNamesInPath(String path)
  4. getJarFile(@Nonnull Class clazz)
  5. getJarFile(Class clazz)
  6. getJarFile(Class clazz)
  7. getJarFile(final ClassLoader loader)
  8. getJarFile(String classPath)
  9. getJarFileByResourceName(Class clazz, String resourceName)