Attempts to extract a name of a missing class loader dependency from an exception such as {@link NoClassDefFoundError} or {@link ClassNotFoundException}.
96
public static String getNameOfMissingClassLoaderDependency(Throwable e) {
        if (e instanceof NoClassDefFoundError) {
            // NoClassDefFoundError sometimes includes CNFE as the cause. Since CNFE has a better formatted class name
            // and may also include classloader info, we prefer CNFE's over NCDFE's message.
            if (e.getCause() instanceof ClassNotFoundException) {
                return getNameOfMissingClassLoaderDependency(e.getCause());
            }
            if (e.getMessage() != null) {
                return e.getMessage().replace('/', '.');
            }
        }
        if (e instanceof ClassNotFoundException) {
            if (e.getMessage() != null) {
                return e.getMessage();
            }
        }
        if (e.getCause() != null) {
            return getNameOfMissingClassLoaderDependency(e.getCause());
        } else {
            return "[unknown]";
        }
    }
211705
private static Class<?> name2class(ClassLoader cl, String name)
			throws ClassNotFoundException {
		int c = 0, index = name.indexOf('[');
		if (index > 0) {
			c = (name.length() - index) / 2;
			name = name.substring(0, index);
		}
		if (c > 0) {
			StringBuilder sb = new StringBuilder();
			while (c-- > 0)
				sb.append("[");

			if ("void".equals(name))
				sb.append(JVM_VOID);
			else if ("boolean".equals(name))
				sb.append(JVM_BOOLEAN);
			else if ("byte".equals(name))
				sb.append(JVM_BYTE);
			else if ("char".equals(name))
				sb.append(JVM_CHAR);
			else if ("double".equals(name))
				sb.append(JVM_DOUBLE);
			else if ("float".equals(name))
				sb.append(JVM_FLOAT);
			else if ("int".equals(name))
				sb.append(JVM_INT);
			else if ("long".equals(name))
				sb.append(JVM_LONG);
			else if ("short".equals(name))
				sb.append(JVM_SHORT);
			else
				sb.append('L').append(name).append(';'); // "java.lang.Object"
															// ==>
															// "Ljava.lang.Object;"
			name = sb.toString();
		} else {
			if ("void".equals(name))
				return void.class;
			else if ("boolean".equals(name))
				return boolean.class;
			else if ("byte".equals(name))
				return byte.class;
			else if ("char".equals(name))
				return char.class;
			else if ("double".equals(name))
				return double.class;
			else if ("float".equals(name))
				return float.class;
			else if ("int".equals(name))
				return int.class;
			else if ("long".equals(name))
				return long.class;
			else if ("short".equals(name))
				return short.class;
		}

		if (cl == null)
			cl = getClassLoader();
		Class<?> clazz = NAME_CLASS_CACHE.get(name);
		if (clazz == null) {
			clazz = Class.forName(name, true, cl);
			NAME_CLASS_CACHE.put(name, clazz);
		}
		return clazz;
	}
209286
public static Class<?> classForName(String name) throws ClassNotFoundException {
		
		ClassLoader cl = getClassLoader();
		try {
			if (cl != null) {
				return cl.loadClass(name);
			}
		} catch (ClassNotFoundException e) {
			// Ignore and try using Class.forName()
		}
		return Class.forName(name);
	}
1164840
private final Class loadClass2( String name ) throws ClassNotFoundException {
    Class z = findLoadedClass(name); // Look for pre-existing class
    if( z != null ) return z;
    if( _weaver == null ) _weaver = new Weaver();
    z = _weaver.weaveAndLoad(name, this);    // Try the Happy Class Loader
    if( z != null ) {
      // Occasionally it's useful to print out class names that are actually Weaved.
      // Leave this commented out println here so I can easily find it for next time.
      //   System.out.println("WEAVED: " + name);
      return z;
    }
    z = getParent().loadClass(name); // Try the parent loader.  Probably the System loader.
    if( z != null ) return z;
    return z;
  }
416282
public Class loadClass(String name)
    {
        try
        {
            return classLoader.loadClass( name );
        }
        catch (ClassNotFoundException notFound)
        {
            return null;
        }
        catch (NoClassDefFoundError notFound)
        {
            return null;
        }
    }
1174805
public static Class loadClass(Class loadClass,String name)
        throws ClassNotFoundException
    {
        ClassNotFoundException cnfe=null;
        ClassLoader loader=Thread.currentThread().getContextClassLoader();
        if (loader!=null)
        {
            try
            {
               return loader.loadClass(name);
            }
            catch (ClassNotFoundException e)
            {
               cnfe=e;
            }
        }

        loader=loadClass.getClassLoader();
        if (loader!=null)
        {
            try
            {
               return loader.loadClass(name);
            }
            catch (ClassNotFoundException e)
            {
               if(cnfe==null)cnfe=e;
            }
        }


       try
       {
            return Class.forName(name);
       }
       catch (ClassNotFoundException e)
       {
            if(cnfe==null)cnfe=e;
	    throw cnfe;
       }

    }
294089
public Class<?> loadClassFrom(String name, AbstractClassLoader first) throws ClassNotFoundException {
		// try on the system one
		try { return AppClassLoader.class.getClassLoader().loadClass(name); }
		catch (ClassNotFoundException e) { /* not found. */ }
		Class<?> c = null;
		// check it is not loaded on one of the library
		for (int i = 0; i < libs.size(); i++) {
    		AbstractClassLoader cl = libs.get(i);
    		c = cl.isLoaded(name);
    		if (c != null) return c;
    	}
    	// try with the first one
    	if (first != null) {
    		try {
    			c = first.loadClassInLibrary(name);
    			if (c != null) return c;
    		} catch (FileNotFoundException e) {
    			// not found
    		} catch (IOException e) {
    			throw new ClassNotFoundException(e.getMessage());
    		}
    	}
    	// then, try on other libraries
    	for (int i = 0; i < libs.size(); i++) {
    		AbstractClassLoader cl = libs.get(i);
    		if (cl == first) continue;
    		try {
    			c = cl.loadClassInLibrary(name);
    			if (c != null) return c;
    		} catch (FileNotFoundException e) {
    			// not found
    		} catch (IOException e) {
    			throw new ClassNotFoundException(e.getMessage());
    		}
    	}
		StringBuilder msg = new StringBuilder(512);
		msg.append("Class not found: ").append(name);
		msg.append("\r\nFrom class loader: ").append(first);
		msg.append("\r\nlibraries currently registered:");
		for (int i = 0; i < libs.size(); i++)
			msg.append("\r\n - ").append(libs.get(i).toString());
		throw new ClassNotFoundException(msg.toString());
	}

	/** Load a resource. */
	@SuppressWarnings("resource")
	public IO.Readable getResourceIO(String name, byte priority) {
		if (name.length() == 0) return null;
		if (name.charAt(0) == '/') name = name.substring(1);
		IO.Readable io = null;
    	for (int i = 0; i < libs.size(); i++) {
    		AbstractClassLoader cl = libs.get(i);
   			try { io = cl.open(name, priority); }
   			catch (IOException e) { /* ignore */ }
    		if (io != null) return io;
    	}
       	// then try on the core one
        InputStream in = AppClassLoader.class.getClassLoader().getResourceAsStream(name);
        if (in == null) return null;
        return new IOFromInputStream(in, name, Threading.getUnmanagedTaskManager(), priority);
	}
996626
private final CClassLoader getLoaderByName(final String name) {
		try {

			CClassLoader loader = (CClassLoader) this.childrenMap.get(name);

			if (loader == null) {
				loader = CClassLoader.createLoader(this, name);
				this.childrenMap.put(name, loader);
			}

			return loader;
		} finally {
			try {

			} catch (final Exception ignore) {
			}
		}
	}
92646
public static final String extractSimpleClassName(String className) {
		if (className == null) {
			throw new NullPointerException();
		}
		
		final int idx = className.lastIndexOf('.');
		if (idx == -1) {
			return className;
		} else {
			return className.substring(idx + 1);
		}
	}
672306
@SuppressWarnings("rawtypes")  
  public Class getException(ClassLoader warClassLoader) {
    try {
      return Class.forName(errorParam, true, warClassLoader);
    } catch (Exception e) {
      return null;
    }
  }
1107980
public static Class<?> classForName(final String name, final ClassLoader loader)
      throws ClassNotFoundException {
    if (name.startsWith("[")) {
      throw new UnsupportedOperationException("No support for arrays, etc.  Name was: " + name);
    } else if (name.equals("boolean")) {
      return boolean.class;
    } else if (name.equals("byte")) {
      return byte.class;
    } else if (name.equals("char")) {
      return char.class;
    } else if (name.equals("short")) {
      return short.class;
    } else if (name.equals("int")) {
      return int.class;
    } else if (name.equals("long")) {
      return long.class;
    } else if (name.equals("float")) {
      return float.class;
    } else if (name.equals("double")) {
      return double.class;
    } else if (name.equals("void")) {
      return void.class;
    } else {
      return loader.loadClass(name);
    }
  }
986551
public Class<?> findClass(String className) throws ClassNotFoundException {
        for (String skip : SKIP_CLASSES) {
            if (skip.equals(className)) {
                return null;
            }
        }

        for (ClassLoader classLoader : getClassLoaders()) {
            try {
                return classLoader.loadClass(className);
            } catch (ClassNotFoundException e) {
                // ignore
            }
        }
        return Class.forName(className);
    }
637471
public JavaClass lookupClass(@Nonnull @DottedClassName String className) throws ClassNotFoundException {
        try {
            if (className.length() == 0) {
                throw new IllegalArgumentException("Class name is empty");
            }
            if (!ClassName.isValidClassName(className)) {
                throw new ClassNotFoundException("Invalid class name: " + className);
            }
            return Global.getAnalysisCache().getClassAnalysis(JavaClass.class,
                    DescriptorFactory.instance().getClassDescriptor(ClassName.toSlashedClassName(className)));
        } catch (CheckedAnalysisException e) {
            throw new ClassNotFoundException("Class not found: " + className, e);
        }
    }
829225
private static Class<?> tryLoadInnerClass(String name, ClassLoader classLoader, boolean isInitialized) {
		// 尝试获取内部类，例如java.lang.Thread.State =》java.lang.Thread$State
		final int lastDotIndex = name.lastIndexOf(PACKAGE_SEPARATOR);
		if (lastDotIndex > 0) {// 类与内部类的分隔符不能在第一位，因此>0
			final String innerClassName = name.substring(0, lastDotIndex) + INNER_CLASS_SEPARATOR + name.substring(lastDotIndex + 1);
			try {
				return Class.forName(innerClassName, isInitialized, classLoader);
			} catch (ClassNotFoundException ex2) {
				// 尝试获取内部类失败时，忽略之。
			}
		}
		return null;
	}
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;
    }
623054
private ClassLoader getClassLoader()
        throws MojoExecutionException
    {
        List<URL> classpathURLs = new ArrayList<URL>();
        this.addRelevantPluginDependenciesToClasspath( classpathURLs );
        this.addRelevantProjectDependenciesToClasspath( classpathURLs );
        this.addAdditionalClasspathElements( classpathURLs );
        
        if (outputDirectory.isDirectory()) {
        	// load compiled classes
        	Collection listFiles = FileUtils.listFiles(outputDirectory, new String[]{"class"}, true);
        	for (Object object : listFiles) {
        		if (object instanceof File) {
        			File f = (File) object;
        			if (f.isFile()) {
        				try {
        					classpathURLs.add(f.toURI().toURL());
        				} catch (Exception e) {
        					// TODO: handle exception
        				}
        			}
        		}
        	}
        }
        
        
        return new URLClassLoader( classpathURLs.toArray( new URL[classpathURLs.size()] ) , getClass().getClassLoader());
    }
1268403
public Class getClassByName(String name)
	{

		if (name.indexOf(".") != -1)
		{
			try
			{
				return Class.forName(name,true,gt.getClassLoader());
			}
			catch (ClassNotFoundException e)
			{
				return null;
			}

		}
		else
		{
			Class cls = map.get(name);
			if (cls == null)
			{
				for (String pkg : pkgList)
				{
					try
					{
						String clsName = pkg.concat(name);
						cls = Class.forName(clsName,true,gt.getClassLoader());
						map.put(name, cls);
						return cls;

					}
					catch (Exception ex)
					{
						// continue;
					}
				}
				return null;
			}
			else
			{
				return cls;
			}

		}

	}