Java Class Loader createClassLoader(String fileName)

Here you can find the source of createClassLoader(String fileName)

Description

create Class Loader

License

Open Source License

Declaration

static public URLClassLoader createClassLoader(String fileName) 

Method Source Code

//package com.java2s;
/**//from  www.j a  v  a  2s  .  c  o m
 * This file is part of Spritnesse.
 * <p/>
 * 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.0 of the License, or (at your option) any later version.
 * <p/>
 * 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.
 * <p/>
 * You should have received a copy of the GNU Lesser General Public License along with this library.
 * <p/>
 * Copyright (c) 2014, Andrew Oxenburgh, All rights reserved.
 */

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

public class Main {
    static public URLClassLoader createClassLoader(String fileName) {
        String urlPath = makeUrlPath(fileName);
        URL url = null;
        try {
            url = new URL(urlPath);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
        URLClassLoader loader = URLClassLoader.newInstance(new URL[] { url });

        return loader;
    }

    static private String makeUrlPath(String fileName) {
        String path = new File(".").getAbsolutePath();
        path = path.substring(0, path.length() - 2);
        return "file:///" + path + "/" + fileName;
    }
}

Related

  1. addDirectoryToClassLoader(ClassLoader loader, File directory)
  2. addFileToSystemClassLoader(String s)
  3. createClassloader(File libDir, ClassLoader cl)
  4. createClassLoader(File root)
  5. createClassLoader(final String[] cpEntries)
  6. createFallbackClassLoader(Collection files)
  7. dumpClassLoader(ClassLoader cl, PrintWriter out)
  8. getClass(Object classLoaderMakedObject, File file, String targetClass)
  9. getClassInputStream(String className, ClassLoader cl)