Java Class Loader getClass(Object classLoaderMakedObject, File file, String targetClass)

Here you can find the source of getClass(Object classLoaderMakedObject, File file, String targetClass)

Description

get Class

License

Open Source License

Declaration

public static Class<?> getClass(Object classLoaderMakedObject, File file, String targetClass) throws Exception 

Method Source Code

//package com.java2s;
/*/*  w  w  w . j  a va 2  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.net.URL;
import java.net.URLClassLoader;

public class Main {

    public static Class<?> getClass(Object classLoaderMakedObject, File file, String targetClass) throws Exception {
        URL[] urls = { file.toURI().toURL() };
        URLClassLoader classLoader = (URLClassLoader) classLoaderMakedObject.getClass().getClassLoader();
        ClassLoader loader = URLClassLoader.newInstance(urls, classLoader);
        Class<?> clazz = loader.loadClass(targetClass);
        return clazz;
    }
}

Related

  1. createClassLoader(File root)
  2. createClassLoader(final String[] cpEntries)
  3. createClassLoader(String fileName)
  4. createFallbackClassLoader(Collection files)
  5. dumpClassLoader(ClassLoader cl, PrintWriter out)
  6. getClassInputStream(String className, ClassLoader cl)
  7. getClassLoader()
  8. getClassLoader(File[] directories)
  9. getClassLoader(String path)