Java Utililty Methods ClassPath Add

List of utility methods to do ClassPath Add

Description

The list of methods to do ClassPath Add are organized into topic(s).

Method

voidaddAllFilesToExtClassLoaderClasspathWithReg(String sDir, String regexpFilter)
Adds all files in a directory to the Ext classloader's classpath
String[] asFilteredFiles = getAllFilesMatchingThisPatternIgnoreCase(sDir, regexpFilter);
for (int i = 0; i < asFilteredFiles.length; i++) {
    String filteredFilePath = new File(sDir, asFilteredFiles[i]).getAbsolutePath();
    addFileToExtClassLoaderClasspath(filteredFilePath);
voidaddBundleToClassPath(String bundleId)
add Bundle To Class Path
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
if (systemClassLoader instanceof URLClassLoader) {
    URLClassLoader classLoader = (URLClassLoader) systemClassLoader;
    String path = getBundlePath(classLoader, bundleId);
    addFolderToClassPath(classLoader, path);
voidaddClassPath(File filePath)
Adds the specified file path to the current thread's class loader.
ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader();
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { filePath.toURI().toURL() },
        currentThreadClassLoader);
Thread.currentThread().setContextClassLoader(urlClassLoader);
voidaddClasspath(String path)
add Classpath
File file = new File(path);
if (file.exists()) {
    URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    Class<URLClassLoader> urlClass = URLClassLoader.class;
    Method method = urlClass.getDeclaredMethod("addURL", new Class[] { URL.class });
    method.setAccessible(true);
    method.invoke(urlClassLoader, new Object[] { file.toURI().toURL() });
voidaddClassPath2ClassLoader(ClassLoader cl, String path)
Add specify path to specify loader
try {
    addURL.invoke(cl, new File(path).toURL());
} catch (IllegalArgumentException e) {
    e.printStackTrace();
} catch (MalformedURLException e) {
    e.printStackTrace();
} catch (IllegalAccessException e) {
    e.printStackTrace();
...
voidaddClasspathEntries(Collection cpEntries)
Add these new classpath entries to resolve against.
List<URL> cp = new ArrayList<URL>();
for (String cpEntry : cpEntries) {
    try {
        cp.add(new File(cpEntry).toURI().toURL());
    } catch (MalformedURLException e) {
URL[] classPath = cp.toArray(new URL[0]);
...
URLClassLoaderaddClassPathItems(String[] cpItems)
Adds the items to the classPath of the system classLoader
return addClassPathItems(ClassLoader.getSystemClassLoader(), cpItems);
voidaddDirToClasspath(File directory)
Adds the jars in the given directory to classpath
for (File file : directory.listFiles()) {
    addURL(file.toURI().toURL());
voidaddDirToClasspath(File directory)
Adds the jars in the given directory to classpath
if (directory.exists()) {
    File[] files = directory.listFiles();
    for (File file : files) {
        addURL(file.toURI().toURL());
voidaddPathToClassPath(String s)
add Path To Class Path
File f = new File(s);
URL u = f.toURI().toURL();
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class urlClass = URLClassLoader.class;
Method method = urlClass.getDeclaredMethod("addURL", new Class[] { URL.class });
method.setAccessible(true);
method.invoke(urlClassLoader, new Object[] { u });