1

我想在下面添加配置文件/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);
4

1 回答 1

0

我成功了

谢谢Darcy Qiu很好URL[] url={new URL("file:///home/nameuser/.myProject/conf/")};,我不得不做而不是URL[] url={new URL("file:///home/nameuser/.myProject/conf/myfile")};

于 2013-02-22T09:46:26.373 回答