Java Jar File Load loadJarInSystemClassLoader(File out)

Here you can find the source of loadJarInSystemClassLoader(File out)

Description

load Jar In System Class Loader

License

Apache License

Declaration

public static void loadJarInSystemClassLoader(File out) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

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

public class Main {
    public static void loadJarInSystemClassLoader(File out) {
        try {//w w w. jav a2  s . c  om
            URLClassLoader systemClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
            Method declaredMethod = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class });
            declaredMethod.setAccessible(true);
            declaredMethod.invoke(systemClassLoader, out.toURI().toURL());
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
}

Related

  1. loadClassFromJar(String jarAbsolutePath, String className)
  2. loadJar(File jar)
  3. loadJar(String jarPath)
  4. loadJar(String path)
  5. loadJarFile(File jarFile, String className)
  6. loadJarIntoClasspath(File jarFile)
  7. loadJarsFromDir(final File dir)