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

ListfindAllPluginJars0(final File pluginPath)
find All Plugin Jars
final List<URL> jars = new ArrayList<URL>();
for (final File entry : pluginPath.listFiles()) {
    if (entry.isDirectory()) {
        jars.addAll(findAllPluginJars0(entry));
    } else if (entry.isFile() && entry.getName().toLowerCase().endsWith(".jar")) {
        jars.add(entry.toURI().toURL());
return jars;
URLfindClassJar(final Class aClass)
The retrieves the URL of the Jar file containing the given class
return aClass.getResource('/' + aClass.getName().replace('.', '/') + ".class");
StringfindContainingJar(@SuppressWarnings("rawtypes") Class my_class, ClassLoader loader)
find Containing Jar
String class_file = my_class.getName().replaceAll("\\.", "/") + ".class";
return findContainingJar(class_file, loader);
StringfindContainingJar(Class my_class)
Find a jar that contains a class of the same name, if any.
ClassLoader loader = my_class.getClassLoader();
String class_file = my_class.getName().replaceAll("\\.", "/") + ".class";
try {
    for (Enumeration itr = loader.getResources(class_file); itr.hasMoreElements();) {
        URL url = (URL) itr.nextElement();
        if ("jar".equals(url.getProtocol())) {
            String toReturn = url.getPath();
            if (toReturn.startsWith("file:")) {
...
StringfindContainingJar(Class clazz)
find Containing Jar
ClassLoader loader = clazz.getClassLoader();
String classFile = clazz.getName().replaceAll("\\.", "/") + ".class";
try {
    for (final Enumeration<URL> itr = loader.getResources(classFile); itr.hasMoreElements();) {
        final URL url = itr.nextElement();
        if ("jar".equals(url.getProtocol())) {
            String path = url.getPath();
            if (path.startsWith("file:")) {
...
StringfindContainingJar(Class clazz)
find Containing Jar
return findContainingJar(clazz, null);
StringfindContainingJar(Class myClass, Map packagedClasses)
Find a jar that contains a class of the same name, if any.
ClassLoader loader = myClass.getClassLoader();
String classFile = myClass.getName().replaceAll("\\.", "/") + ".class";
for (Enumeration<URL> itr = loader.getResources(classFile); itr.hasMoreElements();) {
    URL url = itr.nextElement();
    if ("jar".equals(url.getProtocol())) {
        String toReturn = url.getPath();
        if (toReturn.startsWith("file:")) {
            toReturn = toReturn.substring("file:".length());
...
FilefindContainingJar(ClassLoader classLoader, String resourceName)
find Containing Jar
File jarFile;
URL url = Thread.currentThread().getContextClassLoader().getResource(resourceName);
if ("jar".equals(url.getProtocol())) { 
    String path = url.getPath();
    int index = path.indexOf("!/"); 
    if (index >= 0) {
        try {
            String jarPath = path.substring(0, index);
...
StringfindJar(Class klass)
find Jar
String className = klass.getName();
ClassLoader cl = klass.getClassLoader();
return findJar(className, cl);
StringfindJar(Class my_class)
find Jar
ClassLoader loader = my_class.getClassLoader();
String class_file = my_class.getName().replaceAll("\\.", "/") + ".class";
try {
    for (Enumeration<?> itr = loader.getResources(class_file); itr.hasMoreElements();) {
        URL url = (URL) itr.nextElement();
        if ("jar".equals(url.getProtocol())) {
            String toReturn = url.getPath();
            if (toReturn.startsWith("file:")) {
...