我想在运行时将 /home/nameuser/.myProject/conf
下的配置文件添加到类路径中。
我尝试使用 URLClassLoader
但没有成功。
URL[] url={new URL("file://foo")};
URLClassLoader loader = new URLClassLoader(url);
或
ClassLoader currentThreadClassLoader
= Thread.currentThread().getContextClassLoader();
// Add the conf dir to the classpath
// Chain the current thread classloader
URLClassLoader urlClassLoader
= new URLClassLoader(new URL[]{new File("mtFile").toURL()},
currentThreadClassLoader);
// Replace the thread classloader - assumes
// you have permissions to do so
Thread.currentThread().setContextClassLoader(urlClassLoader);
最佳答案
我成功了
谢谢 Darcy Qiu 很好 URL[] url={new URL("file:///home/nameuser/.myProject/conf/")};
我必须做并且不是 URL[] url={new URL("file:///home/nameuser/.myProject/conf/myfile")};
关于java - 动态修改类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15007794/