【问题标题】:Java on Pi arm64 with JInput带有 JInput 的 Pi arm64 上的 Java
【发布时间】:2021-10-03 13:38:04
【问题描述】:

我仍在尝试让我的蓝牙控制器使用 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 文件

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

【问题讨论】:

  • 加载库失败:java.library.path 中没有 jinput-linux64 为什么要尝试在 Windows 上使用名称中包含“linux64”的库? Windows 库将包含一个 .dll
  • Windows 版本应该为 64 位系统生成 jinput-dx8_64.dll。该文件是必需的,包含它的目录将是 java.library.path 的值(或值的一部分)
  • 很抱歉给您带来了困惑。当然,我在 arm64 Raspberry pi 上运行代码,而不是在我的 Windows 机器上。 windows机器只是用来编译的。
  • 你可以交叉编译到那个盒子上吗?
  • 我在linux上安装了正确的依赖libjinput-java,也可以运行这个库的测试jar文件。但我无法创建自己的 jar 文件,我通过 gradle 文件引用 jinput

标签: java jinput


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-08-20
    • 1970-01-01
    • 2014-01-18
    • 2011-01-04
    • 1970-01-01
    • 1970-01-01
    • 2023-01-18
    • 2019-03-22
    • 1970-01-01
    相关资源
    最近更新 更多