Java Class Loader createClassLoader(final String[] cpEntries)

Here you can find the source of createClassLoader(final String[] cpEntries)

Description

Builds a ClassLoader for a given classpath.

License

Open Source License

Parameter

Parameter Description
cpEntries classpath entries

Return

the new ClassLoader

Declaration

public static ClassLoader createClassLoader(final String[] cpEntries) 

Method Source Code


//package com.java2s;
// License as published by the Free Software Foundation; either

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

public class Main {
    /**/*w w  w  . j a va  2s  .c  o  m*/
     * Builds a ClassLoader for a given classpath.
     * @param cpEntries classpath entries
     * @return the new ClassLoader
     */
    public static ClassLoader createClassLoader(final String[] cpEntries) {
        final URL[] cpUrls = new URL[cpEntries.length];
        for (int i = 0; i < cpEntries.length; i++) {
            String cpEntry = cpEntries[i];
            File entry = new File(cpEntry);
            try {
                URL url = entry.toURI().toURL();
                cpUrls[i] = url;
            } catch (MalformedURLException ex) {
                throw new IllegalArgumentException("Cannot create classLoader from classpath entry " + entry, ex);
            }
        }
        final URLClassLoader classPathLoader = new URLClassLoader(cpUrls);
        return classPathLoader;
    }
}

Related

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