Java ClassPath Add addToClassPath(File file)

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

Description

add To Class Path

License

Apache License

Declaration

public static void addToClassPath(File file) 

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 addToClassPath(File file) {
        if (!file.exists()) {
            throw new RuntimeException(file + " not found");
        }//  ww w. j  a v a 2 s.c om
        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) {
            throw new RuntimeException("Error adding JRI.jar to classpath");
        }
    }
}

Related

  1. addClassPathItems(String[] cpItems)
  2. addDirToClasspath(File directory)
  3. addDirToClasspath(File directory)
  4. addPathToClassPath(String s)
  5. addToClasspath(File f)
  6. addToClasspath(File file)
  7. addToClassPath(String s)
  8. addToClassPath(Vector cpV, String dir)