Java ClassPath Add addClassPath2ClassLoader(ClassLoader cl, String path)

Here you can find the source of addClassPath2ClassLoader(ClassLoader cl, String path)

Description

Add specify path to specify loader

License

Open Source License

Parameter

Parameter Description
cl ClassLoader
path String

Declaration

public static void addClassPath2ClassLoader(ClassLoader cl, String path) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2005-2011 eBay Inc./*from  ww w. j a va2s  .  com*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 *******************************************************************************/

import java.io.File;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    /**
     * The add url method loader.
     */
    private static Method addURL;

    /**
     * Add specify path to specify loader
     * 
     * @param cl {@link ClassLoader}
     * @param path String
     */
    public static void addClassPath2ClassLoader(ClassLoader cl, String path) {
        try {
            addURL.invoke(cl, new File(path).toURL());
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    /**
     * Add specify path to specify loader
     * 
     * @param cl {@link ClassLoader}
     * @param path String
     */
    public static void addClassPath2ClassLoader(ClassLoader cl, URL path) {
        try {
            addURL.invoke(cl, path);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. addAllFilesToExtClassLoaderClasspathWithReg(String sDir, String regexpFilter)
  2. addBundleToClassPath(String bundleId)
  3. addClassPath(File filePath)
  4. addClasspath(String path)
  5. addClasspathEntries(Collection cpEntries)
  6. addClassPathItems(String[] cpItems)
  7. addDirToClasspath(File directory)
  8. addDirToClasspath(File directory)