Here you can find the source of addClassPathItems(String[] cpItems)
Parameter | Description |
---|---|
cpItems | classPath items to be added |
Parameter | Description |
---|---|
MalformedURLException | an exception |
public static URLClassLoader addClassPathItems(String[] cpItems) throws MalformedURLException
//package com.java2s; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; public class Main { /**/* ww w . j a va2 s . co m*/ * Adds the items to the classPath of the system classLoader * * @param cpItems * classPath items to be added * @return extended URLClassLoader * * @throws MalformedURLException */ public static URLClassLoader addClassPathItems(String[] cpItems) throws MalformedURLException { return addClassPathItems(ClassLoader.getSystemClassLoader(), cpItems); } /** * Adds to the give classLoader the class path items * * @param classLoader * any class loader, you can use * ClassLoader.getSystemClassLoader() * @param cpItems * paths to items to be added * @return the extended URLClassLoader * * @throws MalformedURLException */ public static URLClassLoader addClassPathItems(ClassLoader classLoader, String[] cpItems) throws MalformedURLException { URL[] urls = new URL[cpItems.length]; for (int i = 0; i < cpItems.length; ++i) { File f = new File(cpItems[i]); urls[i] = f.toURI().toURL(); } return new URLClassLoader(urls, classLoader); } }