IntelliJ, JInput and the java.library.path

638 Views Asked by At

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.

1

There are 1 best solutions below

0
J.E.Tkaczyk On

I use this method below to set the path dynamically just before the DLL is needed by some object. It is called as follows:

setDllLibraryPath("C:/yourPathToDLLs")

Method to set library path

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);
    }
}