Here you can find the source of addClassPath2ClassLoader(ClassLoader cl, String path)
Parameter | Description |
---|---|
cl | ClassLoader |
path | String |
public static void addClassPath2ClassLoader(ClassLoader cl, String path)
//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(); } } }