Java ClassLoader add(File file)

Here you can find the source of add(File file)

Description

add

License

Open Source License

Declaration

public static void add(File file) 

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 {
    private static final URLClassLoader systemClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();

    public static void add(URL url) {
        try {//  w  ww.j  ava  2 s .  c o  m
            Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);

            method.setAccessible(true);
            method.invoke(systemClassLoader, url);
        } catch (Exception ex) {
            // ignore exception
        }
    }

    public static void add(File file) {
        try {
            add(file.toURI().toURL());
        } catch (Exception ex) {
            // ignore exception
        }
    }
}

Related

  1. addDirectory(File directory)
  2. AddFile(File f)
  3. addFile(File file)
  4. addFile(String s)