How can I build and run my gradle project, when it needs binary library files (JInput)?

馋奶兔 提交于 2019-12-02 10:25:53

Yes, there is an additional step. I followed these instructions: Getting started with JInput

The JInput dependencies you are linking in gradle file only set up the API for what methods/classes can be accessed. The actual machine code for those is inside the dynamic link libraries...DLL, i.e. the binaries.

First you download the DLLs:JInput DLL download into a folder.

Then you link the path to this folder with either a command line argument (-Djava.library.path= "C:/pathToLibrary" or dynamically by calling the following method before your class requiring it is created.

public static void setDllLibraryPath(String resourceStr) {
    try {
        System.setProperty("java.library.path", resourceStr);
        //System.setProperty("java.library.path", "/lib/x64");//for example

        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);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!