0
내 프로젝트에서 런타임에 java.library.path를 구성해야합니다. 자바는 나에게 그런 능력을 주느냐?런타임시 java.library.path를 어떻게 구성 할 수 있습니까?
내 프로젝트에서 런타임에 java.library.path를 구성해야합니다. 자바는 나에게 그런 능력을 주느냐?런타임시 java.library.path를 어떻게 구성 할 수 있습니까?
첫 번째 옵션은 두 번째 옵션은
/**
* 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);
}
에서 촬영 java.library.path에 경로를 추가 할 다른 값으로 java.library.path를 설정하는 것입니다
질문과 답변을 동시에 게시하는 이유는 무엇입니까? 이 방법으로 문제가 해결되면 질문을 삭제하십시오. – sina72
StackOverflow가 내 질문에 직접 대답 할 수있는 가능성을주는 이유를 묻습니다. :) –