返回指定类的Class Loader用于加载该类的Class Path。返回的字符串以/结尾
181339
public static String getClassRootPath(Class<?> c) {
		String strClassPathName = getClassPathName(c);

		ClassLoader cl = c.getClassLoader();
		if (cl == null)
			return null;

		URL urlClass = cl.getResource(strClassPathName);
		if (urlClass == null)
			return null;

		String strUrl = urlClass.toString();
		return strUrl.substring(0, strUrl.lastIndexOf(strClassPathName));
	}
1278263
public static Class<?> loadClass(String className,
                                     ClassLoader classLoader) {
        Class cls = (Class) classes.get( className );
        if ( cls == null ) {
            try {
                cls = Class.forName( className );
            } catch ( Exception e ) {
                //swallow
            }

            //ConfFileFinder
            if ( cls == null && classLoader != null ) {
                try {
                    cls = classLoader.loadClass( className );
                } catch ( Exception e ) {
                    //swallow
                }
            }

            if ( cls == null ) {
                try {
                    cls = ClassUtils.class.getClassLoader().loadClass( className );
                } catch ( Exception e ) {
                    //swallow
                }
            }

            if ( cls == null ) {
                try {
                    cls = Thread.currentThread().getContextClassLoader().loadClass( className );
                } catch ( Exception e ) {
                    //swallow
                }
            }

            if ( cls == null ) {
                try {
                    cls = ClassLoader.getSystemClassLoader().loadClass( className );
                } catch ( Exception e ) {
                    //swallow
                }
            }

            if ( cls != null ) {
                classes.put( className, cls );
            } else {
                throw new RuntimeException( "Unable to load class '" + className + "'" );
            }
        }
        return cls;
    }
737781
public static String locate(String className, ClassLoader classLoader) {
        String resource = new String(className);

        // format the file name into a valid resource name
        if (!resource.startsWith("/")) {
            resource = "/" + resource;
        }
        resource = resource.replace('.', '/');
        resource = resource + ".class";

        // attempt to locate the file using the class loader
        URL classUrl = classLoader.getResource(resource);
        if (classUrl == null && classLoader == ClasspathUtil.class.getClassLoader()) {
            // Apparently clazz.getResource() works sometimes when clazz.getClassLoader().getResource() does not.
            // TODO: why?
            classUrl = ClasspathUtil.class.getResource(resource);
        }

        if (classUrl == null) {
            return "\nClass not found: [" + className + "]";
        }
        else {
            return classUrl.getFile();
        }
    }
507641
public void addClassLoader(final ClassLoader classLoader) {
        if (this.addedClassLoaders == null) {
            this.addedClassLoaders = new ArrayList<>();
        }
        if (classLoader != null) {
            this.addedClassLoaders.add(classLoader);
        }
    }
277699
private static ClassLoader[] getClassLoaders(ClassLoader classLoader) {
		return new ClassLoader[] { classLoader, Thread.currentThread().getContextClassLoader(), ClassLoaderUtils.class.getClassLoader(),
				systemClassLoader };
	}
1346814
def load(self, path: str) -> ClassFile:
        
        # Try to refresh the class from the cache, loading it from disk
        # if not found.
        try:
            r = self.class_cache.pop(path)
        except KeyError:
            with self.open(f'{path}.class') as source:
                r = self.klass(source)

        r.classloader = self
        # Even if it was found re-set the key to update the OrderedDict
        # ordering.
        self.class_cache[path] = r

        # If the cache is enabled remove every item over N started from
        # the least-used.
        if self.max_cache > 0:
            to_pop = max(len(self.class_cache) - self.max_cache, 0)
            for _ in repeat(None, to_pop):
                self.class_cache.popitem(last=False)

        return r
1099412
private void processClassPath() {
    URL[] classLoaderUrls =
        ((URLClassLoader) Thread.currentThread().getContextClassLoader()).getURLs();
    for (URL url : classLoaderUrls) {
      String path = url.getFile();
      if (path.matches(config.getJarInferRegexStripModelJarName())) {
        String name = path.replaceAll(config.getJarInferRegexStripModelJarName(), "$1");
        LOG(DEBUG, "DEBUG", "model jar name: " + name + "\tjar path: " + path);
        if (!mapModelJarLocations.containsKey(name))
          mapModelJarLocations.put(name, new LinkedHashSet<>());
        mapModelJarLocations.get(name).add(path);
      }
    }
  }
946042
private ClassLoader resolve(Set<? extends File> classPath) {
        ClassLoader classLoader = classLoaders.get(classPath);
        if (classLoader == null) {
            classLoader = doResolve(classPath);
            classLoaders.put(classPath, classLoader);
        }
        return classLoader;
    }
975469
private void doScanPackageClassesByFile(Set<Class<?>> classes,
                                            String packageName, String packagePath, boolean recursive) {
        File dir = new File(packagePath);
        if (!dir.exists() || !dir.isDirectory()) {
            return;
        }
        final boolean fileRecursive = recursive;
        File[] dirfiles = dir.listFiles(new FileFilter() {
            // 自定义文件过滤规则
            public boolean accept(File file) {
                if (file.isDirectory()) {
                    return fileRecursive;
                }
                String filename = file.getName();
                return !(excludeInner && filename.indexOf('$') != -1) && filterClassName(filename);
            }
        });
        for (File file : dirfiles) {
            if (file.isDirectory()) {
                doScanPackageClassesByFile(classes, packageName + "."
                        + file.getName(), file.getAbsolutePath(), recursive);
            } else {
                String className = file.getName().substring(0,
                        file.getName().length() - 6);
                try {
                    classes.add(Thread.currentThread().getContextClassLoader()
                            .loadClass(packageName + '.' + className));

                } catch (ClassNotFoundException e) {
                    throw new LtsRuntimeException(e);
                }
            }
        }
    }
1100876
public void loadClasspath(Resolver resolver) throws IOException {
        Enumeration<URL> e;

        e = getClass().getClassLoader().getResources(MODULE_DESCRIPTOR);
        while (e.hasMoreElements()) {
            loadModule(resolver, e.nextElement());
        }
    }
146257
protected ClassLoader initClassLoader(String baseDirPath)
			throws MalformedURLException {
		File webAppClasses = new File(baseDirPath + WEB_INF_CLASSES_DIR_PATH);
		File[] webAppLibs = new File(baseDirPath + WEB_INF_LIB_DIR_PATH)
				.listFiles(new FilenameFilter() {
					public boolean accept(File dir, String name) {
						return name.endsWith(JAR_FILE_EXTENSION);
					}
				});

		int length = webAppLibs != null ? webAppLibs.length + 1 : 1;
		URL[] urls = new URL[length];

		urls[0] = webAppClasses.toURI().toURL();

		for (int i = 1; i < length; i++) {
			urls[i] = webAppLibs[i - 1].toURI().toURL();
		}

		ClassLoader webAppClassLoader = new JawrBundleProcessorCustomClassLoader(
				urls, getClass().getClassLoader());

		Thread.currentThread().setContextClassLoader(webAppClassLoader);
		return webAppClassLoader;
	}
269703
def load_class_by_path(taskpath):
    

    return getattr(
        importlib.import_module(
            re.sub(
                r"\.[^.]+$",
                "",
                taskpath)),
        re.sub(
            r"^.*\.",
            "",
            taskpath))
769839
protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException
    {
        Class c= findLoadedClass(name);
        ClassNotFoundException ex= null;
        boolean tried_parent= false;
        if (c == null && (_java2compliant || isSystemPath(name)) && !isServerPath(name) && _parent!=null)
        {
            if (log.isTraceEnabled())
                log.trace("try loadClass " + name + " from " + _parent);
            tried_parent= true;
            try
            {
                c= _parent.loadClass(name);
                if (log.isTraceEnabled())
                    log.trace("p0 loaded " + c);
            }
            catch (ClassNotFoundException e)
            {
                ex= e;
            }
        }

        if (c == null)
        {
            if (log.isTraceEnabled())
                log.trace("try findClass " + name + " from " + _urlClassPath);
            try
            {
                c= this.findClass(name);
                if (log.isTraceEnabled())
                    log.trace("cx loaded " + c);
            }
            catch (ClassNotFoundException e)
            {
                ex= e;
            }
        }

        if (c == null && !tried_parent && !isServerPath(name) && _parent!=null)
        {
            if (log.isTraceEnabled())
                log.trace("try loadClass " + name + " from " + _parent);
            c= _parent.loadClass(name);
            if (log.isTraceEnabled())
                log.trace("p1 loaded " + c);
        }
        
        if (c == null)
            throw ex;

        if (resolve)
            resolveClass(c);

        return c;
    }
939405
@Override
  public Class<?> loadClassImpl(String name, boolean resolve)
    throws ClassNotFoundException
  {
    // The JVM has already cached the classes, so we don't need to
    Class<?> cl = findLoadedClass(name);

    if (cl != null) {
      if (resolve) {
        resolveClass(cl);
      }
      
      return cl;
    }

    String className = name;
    
    if (_hasBootClassPath) {
      className = name.replace('.', '/') + ".class";

      if (findPath(className) == null) {
        return null;
      }
    }

    try {
      return super.loadClassImpl(name, resolve);
    } catch (Error e) {
      className = name.replace('.', '/') + ".class";
      
      if (findPath(className) != null) {
        String msg =  (e + "\n  while loading " + name + " in " + this
                       + "\n  which exists in " + findPath(className)
                       + "\n  check for missing dependencies");
        
        log().warning(msg);
      }
      
      throw e;
    } catch (ClassNotFoundException e) {
      className = name.replace('.', '/') + ".class";
      
      if (findPath(className) != null) {
        String msg =  (e + "\n  " + name + " in " + this
            + "\n  exists in " + findPath(className)
            + "\n  check for missing dependencies");
        
        log().fine(msg);
        
        throw new ClassNotFoundException(e.getMessage() + "\n" + msg, e);
      }
      
      throw e;
    }
  }
638982
def load_class_by_name(name: str):
    """"""
    mod_path, _, cls_name = name.rpartition('.')
    mod = importlib.import_module(mod_path)
    cls = getattr(mod, cls_name)
    return cls
267185
private void addClassByJar(ClassLoader classLoader, URL url, String packageName, String packageDirName) {
        // 从url中获取jar，然后从此jar包得到一个枚举类，然后进行迭代.
        JarFile jar;
        try {
            jar = ((JarURLConnection) url.openConnection()).getJarFile();
            Enumeration<JarEntry> entries = jar.entries();
            while (entries.hasMoreElements()) {
                // 获取jar里的一个实体 可以是目录 和一些jar包里的其他文件 如META-INF等文件
                JarEntry entry = entries.nextElement();
                String name = entry.getName();
                // 如果是以/开头的,则获取后面的字符串
                if (name.charAt(0) == '/') {
                    name = name.substring(1);
                }

                // 如果前半部分和定义的包名相同.
                if (name.startsWith(packageDirName)) {
                    int index = name.lastIndexOf('/');
                    // 如果以"/"结尾，则是一个包，获取包名并把"/"替换成"."
                    if (index != -1) {
                        packageName = name.substring(0, index).replace('/', '.');
                    }
                    // 如果可以迭代下去 并且是一个包,如果是一个.class文件 而且不是目录
                    if (index != -1 && name.endsWith(".class") && !entry.isDirectory()) {
                        // 去掉后面的".class" 获取真正的类名
                        String className = name.substring(packageName.length() + 1, name.length() - 6);
                        this.addClassByName(classLoader, packageName + '.' + className);
                    }
                }
            }
        } catch (IOException expected) {
            // 此处不打印堆栈信息.
            log.warn("从jar文件中读取class出错.");
        }
    }
649268
private static String which(String classname, ClassLoader loader) {
        String classnameAsResource = classname.replace('.', '/') + ".class";
        if (loader==null) loader = ClassLoader.getSystemClassLoader();

        URL it = loader.getResource(classnameAsResource);
        return it != null ? it.toString() : null;
    }