import sun.net.www.ParseUtil;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.stream.Collectors;
public class RbcClassLoader extends URLClassLoader {
private RbcClassLoader(URL[] urls) {
super(urls);
}
/**
*
* @param classPath jar文件所在路径
* @return 自定义的类加载器
* @throws IOException
*/
public static ClassLoader getRbcClassLoader(String classPath) throws IOException {
File file = new File(classPath);
if (!file.exists() || !file.isDirectory()) {
throw new IOException("Please check if your path is correct!");
}
//获取所有的该目录下所有的jar文件
File[] jars = Arrays.stream(file.listFiles())
.filter((filePointer) -> filePointer.getName().endsWith(".jar"))
.collect(Collectors.toList()).toArray(new Fil
自定义类加器——加载指定目录下的jar包
最新推荐文章于 2024-04-15 09:19:21 发布
![](https://img-home.csdnimg.cn/images/20240611030827.png)