Java ClassPath createClassPath(File file)

Here you can find the source of createClassPath(File file)

Description

create Class Path

License

Apache License

Declaration

public static URL[] createClassPath(File file) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FilenameFilter;

import java.net.URL;

public class Main {
    public static URL[] createClassPath(File file) throws Exception {
        URL[] urls = null;// w  ww  .j av a 2s  .  c om
        if ((file.exists()) && (file.isDirectory())) {
            String[] jars = file.list(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    if (name.endsWith(".jar")) {
                        return true;
                    }
                    return false;
                }
            });
            if (jars.length != 0) {
                urls = new URL[jars.length];
                for (int i = 0; i < jars.length; i++) {
                    urls[i] = new File(file.getAbsolutePath(), jars[i])
                            .toURI().toURL();
                }
            }
        } else if ((file.exists()) && (!file.isDirectory())) {
            if (file.getName().endsWith(".jar")) {
                urls = new URL[] { file.toURI().toURL() };
            }
        }
        return urls;
    }
}

Related

  1. calculateClassPath(ClassLoader cl)
  2. createClassLoader(List classpathElements, String... paths)
  3. createClassLoader(List libs, boolean useSystemClassPath)
  4. dumpClasspath(ClassLoader loader)
  5. existsInClasspath(Class clazz, String fileName)
  6. existsInClasspath(final String fileName)
  7. fillClassPath(ClassLoader cl, StringBuffer classpath)