Java Path File List nio getClassLoaderFromPaths(ArrayList paths)

Here you can find the source of getClassLoaderFromPaths(ArrayList paths)

Description

get Class Loader From Paths

License

Open Source License

Declaration

public static ClassLoader getClassLoaderFromPaths(ArrayList<Path> paths) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.file.Path;

import java.net.URLClassLoader;
import java.net.URL;

import java.net.MalformedURLException;

import java.util.ArrayList;

public class Main {
    public static ClassLoader getClassLoaderFromPaths(ArrayList<Path> paths) {

        ArrayList<URL> urls = new ArrayList<URL>();

        // for each unzipped project, we need to load the class, this feed the ClassLoader with the
        // path in URL
        for (Path p : paths) {
            try {
                URL url = p.toUri().toURL();
                urls.add(url);//  w w w . j  av a  2 s. c o m
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }
        URL[] urlsArray = new URL[urls.size()];
        // load the test classes from these directories
        urlsArray = urls.toArray(urlsArray); // JVM is not allowed to blindly downcast, so we pass in the object as desired cast
        ClassLoader cl = new URLClassLoader(urlsArray);
        return cl;
    }
}

Related

  1. asPathsList(final File[] files)
  2. compileTreeWithErrors(JavaCompiler compiler, List options, File targetFolder, DiagnosticListener diagnosticListener, boolean addProcessorsToClasspath)
  3. deepListChildren(Path directory)
  4. fileListDeep(Path dir)
  5. findExpectedResultForTestcase(final Path testcase, final LinkedList expectedResults)
  6. getDirectoryList(Path basePath)
  7. getPreorderList(Path root)
  8. getSortedPathList(final Path dir, final boolean dirsFirst)
  9. getTables(final List d1)