Here you can find the source of loadJar(String jarPath)
Parameter | Description |
---|---|
jarPath | the JAR file. |
Parameter | Description |
---|---|
Exception | if the JAR file cannot be loaded. |
public static void loadJar(String jarPath) throws Exception
//package com.java2s; /******************************************************************************* * Copyright 2012-2014 Esri//from w ww .j a va2 s . com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ import java.io.File; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; public class Main { /** * Loads a JAR file so the application can access its classes. * @param jarPath the JAR file. * @throws Exception if the JAR file cannot be loaded. */ public static void loadJar(String jarPath) throws Exception { File f = new File(jarPath); URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); method.setAccessible(true); method.invoke(sysloader, new Object[] { f.toURI().toURL() }); } }