2014-05-23 5 views

답변

0

첫 번째 옵션은 두 번째 옵션은

/** 
* Sets the java library path to the specified path 
* 
* @param path the new library path 
* @throws Exception 
*/ 
public static void setLibraryPath(String path) throws Exception { 
    System.setProperty("java.library.path", path); 

    //set sys_paths to null 
    final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths"); 
    sysPathsField.setAccessible(true); 
    sysPathsField.set(null, null); 
} 

/** 
* Adds the specified path to the java library path 
* 
* @param pathToAdd the path to add 
* @throws Exception 
*/ 
public static void addLibraryPath(String pathToAdd) throws Exception{ 
    final Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths"); 
    usrPathsField.setAccessible(true); 

    //get array of paths 
    final String[] paths = (String[])usrPathsField.get(null); 

    //check if the path to add is already present 
    for(String path : paths) { 
     if(path.equals(pathToAdd)) { 
      return; 
     } 
    } 

    //add the new path 
    final String[] newPaths = Arrays.copyOf(paths, paths.length + 1); 
    newPaths[newPaths.length-1] = pathToAdd; 
    usrPathsField.set(null, newPaths); 
} 

fahd.blog

에서 촬영 java.library.path에 경로를 추가 할 다른 값으로 java.library.path를 설정하는 것입니다
+0

질문과 답변을 동시에 게시하는 이유는 무엇입니까? 이 방법으로 문제가 해결되면 질문을 삭제하십시오. – sina72

+0

StackOverflow가 내 질문에 직접 대답 할 수있는 가능성을주는 이유를 묻습니다. :) –

관련 문제