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

voidaddToClasspath(File f)
Adds a given file to the classpath.
try {
    Method addURL = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class });
    addURL.setAccessible(true);
    URL url = f.toURI().toURL();
    ClassLoader cl = ClassLoader.getSystemClassLoader();
    addURL.invoke(cl, new Object[] { url });
} catch (NoSuchMethodException | SecurityException | MalformedURLException | IllegalAccessException
        | IllegalArgumentException | InvocationTargetException e) {
...
voidaddToClassPath(File file)
add To Class Path
if (!file.exists()) {
    throw new RuntimeException(file + " not found");
try {
    Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class });
    method.setAccessible(true);
    method.invoke(ClassLoader.getSystemClassLoader(), new Object[] { file.toURI().toURL() });
} catch (Exception e) {
...
booleanaddToClasspath(File file)
Adds the specified file to the classpath dynamically
if (!file.exists()) {
    return false;
URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class<URLClassLoader> sysclass = URLClassLoader.class;
try {
    Method method = sysclass.getDeclaredMethod("addURL", new Class[] { URL.class });
    method.setAccessible(true);
...
voidaddToClassPath(String s)
add To Class Path
File f = new File(s);
addToClassPath(f);
voidaddToClassPath(Vector cpV, String dir)
Add all the jar files in a dir to the classpath, represented as a Vector of URLs.
try {
    String cpComp[] = getFilesByExt(dir, ".jar");
    if (cpComp != null) {
        int jarCount = cpComp.length;
        for (int i = 0; i < jarCount; i++) {
            URL url = getURL(dir, cpComp[i]);
            if (url != null)
                cpV.addElement(url);
...