Java ClassPath findClassPathsToEn()

Here you can find the source of findClassPathsToEn()

Description

find Class Paths To En

License

Open Source License

Declaration

public static Enumeration<URL> findClassPathsToEn() 

Method Source Code


//package com.java2s;
import java.io.File;

import java.net.MalformedURLException;
import java.net.URL;

import java.util.ArrayList;
import java.util.Enumeration;

import java.util.Iterator;
import java.util.List;

import java.util.StringTokenizer;

public class Main {
    public static Enumeration<URL> findClassPathsToEn() {
        List<URL> urls = findClassPaths();
        final Iterator<URL> iterator = urls.iterator();
        return new Enumeration<URL>() {

            @Override//from  ww w .java2s .co m
            public boolean hasMoreElements() {
                return iterator.hasNext();
            }

            @Override
            public URL nextElement() {
                return iterator.next();
            }
        };
    }

    @SuppressWarnings("deprecation")
    public static List<URL> findClassPaths() {
        List<URL> list = new ArrayList<URL>();
        String classpath = System.getProperty("java.class.path");
        StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);

        while (tokenizer.hasMoreTokens()) {
            String path = tokenizer.nextToken();
            File fp = new File(path);
            if (!fp.exists())
                throw new RuntimeException("File in java.class.path does not exist: " + fp);
            try {
                list.add(fp.toURL());
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        }
        return list;
    }
}

Related

  1. existsInClasspath(final String fileName)
  2. fillClassPath(ClassLoader cl, StringBuffer classpath)
  3. findClassPaths()
  4. findClassPaths()
  5. findClasspathsByLoader(ClassLoader loader)
  6. findDirectoryFromClasspath(Class cls, String file)
  7. findResourceOnClasspath(String resourceName)
  8. getAvailableClassPathInfo(final ClassLoader classLoader)
  9. getBootstrapClassPath()