参考文档:

https://www.codelast.com/%E5%8E%9F%E5%88%9B-java%E5%8A%A8%E6%80%81%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E7%9B%AE%E5%BD%95%E5%88%B0classpath%E4%B8%AD/

 

public static loadFoldertoClasspath(){

  File programRootDir = new File("./");
    URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    Method add = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
    add.setAccessible(true);
    add.invoke(classLoader, programRootDir.toURI().toURL());


}

 

posted on 2023-10-21 12:11  EZgod  阅读(37)  评论(0编辑  收藏  举报