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

前提是你 提交于 2019-12-04 07:05:45

问题


I'm trying to use JInput for my project, and the library needs some binaries for my application to run.

I've discovered that, the required binaries are inside the library. But still, I get an UnsatisfiedLinkError when doing a gradle run because it cannot find the library binaries.

So I guess I need to unpack the library .jar before running the project? How do I use a library that has native binaries in it?

Here's my build.gradle

plugins {

    id "java"
    id "application"
}

repositories {

    mavenCentral()
}

dependencies {

    // https://mvnrepository.com/artifact/net.java.jinput/jinput
    compile group: 'net.java.jinput', name: 'jinput', version: '2.0.7'
}

EDIT: Here you can see the contents of the library


回答1:


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


来源:https://stackoverflow.com/questions/48783053/how-can-i-build-and-run-my-gradle-project-when-it-needs-binary-library-files-j

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