Java Jar Zip File addJarToClasspath(File jarFile)

Here you can find the source of addJarToClasspath(File jarFile)

Description

add Jar To Classpath

License

Open Source License

Declaration

public static void addJarToClasspath(File jarFile) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

public class Main {
    public static void addJarToClasspath(File jarFile) {
        try {/*from   w w w .jav a 2  s.  c  o m*/
            URL url = jarFile.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[] { url });
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}

Related

  1. addJarLibralyClassPath(Object classLoaderMakedObject, File jarPath)
  2. addJarLibralySystemClassPath(File jarPath)
  3. addJARs(File dir)
  4. addJars(File directory, boolean recursive)
  5. addJarsToClassPath(String jarPath)
  6. addToJar(File source, JarOutputStream jarOutput)
  7. addToJar(JarOutputStream target, String pathInsideJar, File fentry)