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);
用classloader [负载](HTTP:/ /docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html#loadClass%28java.lang.String%29)目标类并使用反射来利用它。 – McDowell 2013-02-21 16:53:38
我的文件不是类但配置文件 – Toisur 2013-02-21 17:06:51
你的代码中有以下内容:'URL [] url = {new URL(“file:///home/nameuser/.myProject/conf/”)};'? – darcyq 2013-02-21 17:18:09