我想在运行时将/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);
答案 0 :(得分:0)
我成功了
感谢Darcy Qiu很好URL[] url={new URL("file:///home/nameuser/.myProject/conf/")};
我必须做而不是URL[] url={new URL("file:///home/nameuser/.myProject/conf/myfile")};