get Jar Url List From Path - Java Reflection

Java examples for Reflection:Jar

Description

get Jar Url List From Path

Demo Code


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

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

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static URL[] getJarUrlListFromPath(String path)
            throws MalformedURLException {
        List<URL> urlList = new ArrayList<URL>();
        File directory = new File(path);
        for (File file : directory.listFiles()) {
            if (file.getName().endsWith(".jar")) {
                urlList.add(new URL("file://" + file.getAbsolutePath()));
            }/*from ww w .  ja v  a  2  s.c  om*/
        }
        return urlList.toArray(new URL[] {});
    }
}

Related Tutorials