Java Jar Zip File addJarLibralySystemClassPath(File jarPath)

Here you can find the source of addJarLibralySystemClassPath(File jarPath)

Description

add Jar Libraly System Class Path

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
public static void addJarLibralySystemClassPath(File jarPath) throws Exception 

Method Source Code

//package com.java2s;
/*// w w  w  . j a v  a2  s .co  m
file of LaBeeFramework
https://www.bee-wkspace.com/
    
Copyright (C) 2016- Naoki Yoshioka (ARTS Laboratory)
http://www.arts-lab.net/dev/
    
This library is free software; you can redistribute it and/or 
modify it under the terms of the GNU Lesser General Public License 
as published by the Free Software Foundation; 
either version 3 of the License, or any later version.
    
This library is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
See the GNU Lesser General Public License for more details.
*/

import java.io.File;

import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

public class Main {

    @SuppressWarnings("unchecked")
    public static void addJarLibralySystemClassPath(File jarPath) throws Exception {

        URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
        @SuppressWarnings("rawtypes")
        Class classClassLoader = URLClassLoader.class;
        Method methodAddUrl = classClassLoader.getDeclaredMethod("addURL", URL.class);

        methodAddUrl.setAccessible(true);
        methodAddUrl.invoke(classLoader, jarPath.toURI().toURL());

    }
}

Related

  1. addFileToJar(File file, ZipOutputStream zipStream, String path)
  2. addFileToJar(File fileOrDirectoryToAdd, File extractedJarPath, JarOutputStream target)
  3. addFileToJar(JarOutputStream jar, InputStream file, String path)
  4. addJar(File path)
  5. addJarLibralyClassPath(Object classLoaderMakedObject, File jarPath)
  6. addJARs(File dir)
  7. addJars(File directory, boolean recursive)
  8. addJarsToClassPath(String jarPath)
  9. addJarToClasspath(File jarFile)