0

I'm working on a java project that uses both Jogl and JInput, and I working in IntelliJ. I'm having some issues with the application not being able to find various DLLs. I know the recommended way is to extract the DLLs to a folder and then point the java.library.path at that folder. Is there a way to include those libraries in project configuration somehow? I'm pulling those files from jCenter, and I'd rather just point the jar files and let JNA do its work.

4

1 回答 1

0

我在下面使用此方法在某个对象需要 DLL 之前动态设置路径。它被称为如下:

setDllLibraryPath("C:/yourPathToDLLs")

设置库路径的方法

public static void setDllLibraryPath(String resourceStr) {
    try {
        System.setProperty("java.library.path", resourceStr);

        Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
        fieldSysPath.setAccessible(true);
        fieldSysPath.set(null, null);//next time path is accessed, the new path will be imported
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    }
}
于 2018-05-30T19:30:03.243 回答