2013-02-21 4 views
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); 
+0

사용하는 클래스 로더 [로드] (HTTP ://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html#loadClass%28java.lang.String%29) 대상 클래스를 사용하고 리플렉션을 사용하여이를 활용합니다. – McDowell

+0

내 파일은 클래스가 아니고 구성 파일입니다. – Toisur

+1

코드에 다음 내용이 있습니까 :'URL [] url = {new URL ("file : ///home/nameuser/.myProject/conf/")};'? – darcyq

답변

0

내가

성공은 다아시 치우에게 감사 내가해야 할 일을했을 및 URL[] url={new URL("file:///home/nameuser/.myProject/conf/")}; 좋은하지 URL[] url={new URL("file:///home/nameuser/.myProject/conf/myfile")};