0

我仍在尝试让我的蓝牙控制器使用 Java 在我的 pi 上工作。我从https://github.com/jinput/jinput找到了项目 jinput并安装了依赖项:

sudo apt-get install libjinput-java libjinput-java-doc libjinput-jni

当我运行测试类时,它正在工作:

 sudo java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/jinput.jar:/user/share/java/jinpu-test.jar net.java.games.input.test.ControllerTextTest

但是,当我使用在我的 Windows 64 位系统上编译的项目时,在 linux 系统上我总是得到错误:

Failed to load library: no jinput-linux64 in java.library.path

尝试以相同的方式运行它:

sudo java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/jinput.jar -jar /home/robot/MyFirstProgram.jar

我不明白其中的区别,所以我认为它可能与 build.gradle 有关

//Gradle file

plugins {
    id 'java'
    id 'eclipse'
    id 'idea'
    id "net.ossindex.audit" version "0.4.5-beta"
    id "com.github.johnrengelman.shadow" version "4.0.3"
    id 'org.hidetake.ssh' version '2.10.1'
}

version = '2.6.0'

// Project definitions

repositories {
    mavenCentral()
    maven {
        url "https://jitpack.io" 
    }
    maven {
        url "https://repo1.maven.org/maven2/"
    }
    maven {
        url "http://oss.sonatype.org/content/repositories/releases"
    }
    maven {
        url "http://oss.sonatype.org/content/repositories/snapshots"
    }

   
}

configurations {
    // configuration that holds jars to include in the jar
    extraLibs
}

dependencies {
    implementation("org.slf4j:slf4j-simple:latest.release")
    implementation("com.github.ev3dev-lang-java:ev3dev-lang-java:latest.release")
    //extraLibs group: "net.sf.bluecove", name:"bluecove", version:"latest.release"
    //extraLibs group: "net.sf.bluecove", name:"bluecove-gpl", version:"latest.release"
    implementation( group: "com.github.hypfvieh", name:"bluez-dbus-parent", version:"0.1.4")
    implementation( group: "com.github.hypfvieh", name: "bluez-dbus", version: "0.1.4")
    implementation( group: "net.java.jinput", name:"jinput", version: "2.0.9")
    extraLibs group: "br.com.criativasoft.opendevice.ext", name:"bluecove", version:"2.1.1-SNAPSHOT"
    extraLibs group: "br.com.criativasoft.opendevice.ext", name:"bluecove-gpl", version:"2.1.1-SNAPSHOT"
    extraLibs group: "br.com.criativasoft.opendevice.ext", name:"bluecove-gpl-arm", version:"2.1.1-SNAPSHOT"
    configurations.compile.extendsFrom(configurations.extraLibs)
}

apply from: './config.gradle'

compileJava.options.encoding = 'UTF-8'

//Compile
compileJava {
    sourceCompatibility = 11
    targetCompatibility = 11
}

//Jar
jar {
    baseName = "${rootProject.name}"
    manifest {
        from file("${projectDir}/src/main/resources/META-INF/MANIFEST.MF")
    }
    
}

task fatJar(type: Jar) {
    manifest.from jar.manifest
    classifier = 'all'
    from {
        configurations.extraLibs.collect { it.isDirectory() ? it : zipTree(it) }
    } {
        exclude "META-INF/*.SF"
        exclude "META-INF/*.DSA"
        exclude "META-INF/*.RSA"
    }
    with jar
}
fatJar.dependsOn shadowJar

apply from: './config.gradle'
apply from: './gradle/deploy.gradle'

有人可以帮我吗?

谢谢

斯蒂芬

编辑:只是为了清楚。我只在 Linux 上运行我的代码,但在 Windows 上使用 VSC 编写和编译 jar 文件

Edit2:我找到了这个https://github.com/SteveSmith16384/jinputtest/blob/master/libs/libjinput-linux64.so,我将其复制到所需的文件夹中,并且运行没有任何问题。但是,我仍然不明白为什么我可以运行本地 jar 文件,但不能运行我编译的。

4

1 回答 1

0

我创建了一个jinput-linux64指向/usr/lib/jni/libjinput. 丑陋,但它对我有用。

于 2022-01-04T05:04:28.667 回答