无法在使用 module-info.java 时加载 FFI 提供程序

huangapple go评论65阅读模式
英文:

Could not load FFI provider when using module-info.java

问题

我的Linux Java应用程序使用蓝牙设备。我使用这个库来与bluez堆栈进行通信:https://github.com/hypfvieh/bluez-dbus。

在我向客户端代码添加module-info.java之前,它运行得非常好。突然间,我遇到了这个错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: could not load FFI provider jnr.ffi.provider.jffi.Provider
    at jnr.ffi@2.1.15/jnr.ffi.provider.InvalidRuntime.newLoadError(InvalidRuntime.java:101)
    ...
    (错误消息截断)
    ...
    at dbus.java@3.2.3/org.freedesktop.dbus.connections.transports.UnixSocketTransport.<init>(UnixSocketTransport.java:32)
    at ...

由于:java.lang.UnsatisfiedLinkError: could not get native definition for type POINTER,原始错误消息如下:java.lang.UnsatisfiedLinkError: could not locate stub library in jar file. Tried [jni/x86_64-Linux/libjffi-1.2.so, /jni/x86_64-Linux/libjffi-1.2.so]

我尝试在module-info.java中要求与此错误相关的所有内容,但没有成功:

module org.example {
    requires dbus.java;
    requires dbus.java.nativefd;
    requires bluecove.linux.custom;
    requires bluez.dbus;
    requires jnr.ffi;
    requires jnr.x86asm;
    requires jnr.posix;
    requires jnr.enxio;
    requires jnr.unixsocket;
    requires jnr.constants;
    requires jnr.a64asm;
}

提前感谢您。

英文:

my Linux Java application uses bluetooth devices. I use this library in order to communicate with bluez stack : https://github.com/hypfvieh/bluez-dbus.

It worked very well until I added module-info.java to my client code. Suddenly I got this error:

> Exception in thread "main" java.lang.UnsatisfiedLinkError: could not load FFI provider jnr.ffi.provider.jffi.Provider
at jnr.ffi@2.1.15/jnr.ffi.provider.InvalidRuntime.newLoadError(InvalidRuntime.java:101)
at jnr.ffi@2.1.15/jnr.ffi.provider.InvalidRuntime.findType(InvalidRuntime.java:42)
at jnr.ffi@2.1.15/jnr.ffi.Struct$NumberField.<init>(Struct.java:872)
at jnr.ffi@2.1.15/jnr.ffi.Struct$Unsigned16.<init>(Struct.java:1240)
at jnr.unixsocket@0.33/jnr.unixsocket.SockAddrUnix$DefaultSockAddrUnix.<init>(SockAddrUnix.java:209)
at jnr.unixsocket@0.33/jnr.unixsocket.SockAddrUnix.create(SockAddrUnix.java:174)
at jnr.unixsocket@0.33/jnr.unixsocket.UnixSocketAddress.<init>(UnixSocketAddress.java:53)
at dbus.java@3.2.3/org.freedesktop.dbus.connections.transports.UnixSocketTransport.<init>(UnixSocketTransport.java:32)
at dbus.java@3.2.3/org.freedesktop.dbus.connections.transports.TransportFactory.createTransport(TransportFactory.java:37)
at dbus.java@3.2.3/org.freedesktop.dbus.connections.AbstractConnection.<init>(AbstractConnection.java:161)
at dbus.java@3.2.3/org.freedesktop.dbus.connections.impl.DBusConnection.<init>(DBusConnection.java:334)
at dbus.java@3.2.3/org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:149)
at dbus.java@3.2.3/org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:169)
at dbus.java@3.2.3/org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:219)
at dbus.java@3.2.3/org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:184)
at bluez.dbus@0.1.3/com.github.hypfvieh.bluetooth.DeviceManager.createInstance(DeviceManager.java:74)
at ...

> Caused by: java.lang.UnsatisfiedLinkError: could not get native definition for type POINTER, original error message follows: java.lang.UnsatisfiedLinkError: could not locate stub library in jar file. Tried [jni/x86_64-Linux/libjffi-1.2.so, /jni/x86_64-Linux/libjffi-1.2.so]
at jffi@1.2.23/com.kenai.jffi.internal.StubLoader.getStubLibraryStream(StubLoader.java:450)
at jffi@1.2.23/com.kenai.jffi.internal.StubLoader.loadFromJar(StubLoader.java:375)
at jffi@1.2.23/com.kenai.jffi.internal.StubLoader.load(StubLoader.java:278)
at jffi@1.2.23/com.kenai.jffi.internal.StubLoader.<clinit>(StubLoader.java:487)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:427)
at jffi@1.2.23/com.kenai.jffi.Init.load(Init.java:68)
at jffi@1.2.23/com.kenai.jffi.Foreign$InstanceHolder.getInstanceHolder(Foreign.java:49)
at jffi@1.2.23/com.kenai.jffi.Foreign$InstanceHolder.<clinit>(Foreign.java:45)
at jffi@1.2.23/com.kenai.jffi.Foreign.getInstance(Foreign.java:103)
at jffi@1.2.23/com.kenai.jffi.Type$Builtin.lookupTypeInfo(Type.java:242)
at jffi@1.2.23/com.kenai.jffi.Type$Builtin.getTypeInfo(Type.java:237)
at jffi@1.2.23/com.kenai.jffi.Type.resolveSize(Type.java:155)
at jffi@1.2.23/com.kenai.jffi.Type.size(Type.java:138)
at jnr.ffi@2.1.15/jnr.ffi.provider.jffi.NativeRuntime$TypeDelegate.size(NativeRuntime.java:178)
at jnr.ffi@2.1.15/jnr.ffi.provider.AbstractRuntime.<init>(AbstractRuntime.java:48)
at jnr.ffi@2.1.15/jnr.ffi.provider.jffi.NativeRuntime.<init>(NativeRuntime.java:57)
at jnr.ffi@2.1.15/jnr.ffi.provider.jffi.NativeRuntime.<init>(NativeRuntime.java:41)
at jnr.ffi@2.1.15/jnr.ffi.provider.jffi.NativeRuntime$SingletonHolder.<clinit>(NativeRuntime.java:53)
at jnr.ffi@2.1.15/jnr.ffi.provider.jffi.NativeRuntime.getInstance(NativeRuntime.java:49)
at jnr.ffi@2.1.15/jnr.ffi.provider.jffi.Provider.<init>(Provider.java:29)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:124)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:346)
at java.base/java.lang.Class.newInstance(Class.java:604)
at jnr.ffi@2.1.15/jnr.ffi.provider.FFIProvider$SystemProviderSingletonHolder.getInstance(FFIProvider.java:68)
at jnr.ffi@2.1.15/jnr.ffi.provider.FFIProvider$SystemProviderSingletonHolder.<clinit>(FFIProvider.java:57)
at jnr.ffi@2.1.15/jnr.ffi.provider.FFIProvider.getSystemProvider(FFIProvider.java:35)
at jnr.ffi@2.1.15/jnr.ffi.Runtime$SingletonHolder.<clinit>(Runtime.java:82)
at jnr.ffi@2.1.15/jnr.ffi.Runtime.getSystemRuntime(Runtime.java:67)
at jnr.unixsocket@0.33/jnr.unixsocket.SockAddrUnix.<init>(SockAddrUnix.java:46)
at jnr.unixsocket@0.33/jnr.unixsocket.SockAddrUnix$DefaultSockAddrUnix.<init>(SockAddrUnix.java:208)
at jnr.unixsocket@0.33/jnr.unixsocket.SockAddrUnix.create(SockAddrUnix.java:174)
at jnr.unixsocket@0.33/jnr.unixsocket.UnixSocketAddress.<init>(UnixSocketAddress.java:53)
at dbus.java@3.2.3/org.freedesktop.dbus.connections.transports.UnixSocketTransport.<init>(UnixSocketTransport.java:32)
at ...

I tried to require everything related to this error in the module-info.java without success:

module org.example {
    requires dbus.java;
    requires dbus.java.nativefd;
    requires bluecove.linux.custom;
    requires bluez.dbus;
    requires jnr.ffi;
    requires jnr.x86asm;
    requires jnr.posix;
    requires jnr.enxio;
    requires jnr.unixsocket;
    requires jnr.constants;
    requires jnr.a64asm;
}

Thank you in advance.

答案1

得分: 1

TL;DR

这对我有用...

java --patch-module jffi={{your.own.location}}/com/github/jnr/jffi/1.3.0/jffi-1.3.0-native.jar …

详细版本

我下载了这个示例项目。它不是一个JPMS项目,但我为其中的四个子项目添加了*module-info.java*文件。

我将项目的*com.github.jnr:jnr-ffi依赖项从2.0.9更新到了2.1.5*,以匹配您在堆栈跟踪中看到的版本。然后我添加了以下依赖...

<dependency>
    <groupId>com.github.hypfvieh</groupId>
    <artifactId>dbus-java</artifactId>
    <version>3.2.3</version>
</dependency>
<dependency>
    <groupId>com.github.hypfvieh</groupId> <artifactId>bluez-dbus</artifactId>
    <version>0.1.3</version>
</dependency>
<dependency>
    <groupId>com.rm5248</groupId>
    <artifactId>dbus-java-nativefd</artifactId>
    <version>1.0</version>
</dependency>

这些是为了接下来能够像您的堆栈跟踪一样定义我的四个*module-info.java*描述符...

module get.pid{
    exports getpid;
    requires dbus.java;
    requires dbus.java.nativefd;
    requires bluez.dbus;
    requires jnr.ffi;
    requires jffi;
    requires jnr.x86asm;
    requires jnr.posix;
    requires jnr.enxio;
    requires jnr.unixsocket;
    requires jnr.constants;
    requires jnr.a64asm;
}

在执行*--patch-module*之前,我运行了其中一个示例项目,并且得到了与您相同的错误。

但是通过以下命令,所有示例应用程序都作为模块完美运行...

java --patch-module jffi={{your.own.location}}/com/github/jnr/jffi/1.3.0/jffi-1.3.0-native.jar --add-modules org.objectweb.asm --add-exports org.objectweb.asm/org.objectweb.asm=jnr.ffi --add-exports org.objectweb.asm/org.objectweb.asm.signature=jnr.ffi --module-path {{path.to.all.the.jars}} -m get.pid/getpid.Getpid

add-modulesadd-exports 也很关键,所以不要漏掉。

英文:

TL;DR

This worked for me…

java --patch-module jffi={{your.own.location}}/com/github/jnr/jffi/1.3.0/jffi-1.3.0-native.jar …

The long version

I downloaded this example project. It's not a JPMS project. But I added module-info.java files to each of the four sub-projects.

I updated the project's com.github.jnr:jnr-ffi dependency from 2.0.9 to 2.1.5 to match the version I see in your stack trace. And I added the following dependencies…

…
&lt;dependency&gt;
    &lt;groupId&gt;com.github.hypfvieh&lt;/groupId&gt;
    &lt;artifactId&gt;dbus-java&lt;/artifactId&gt;
    &lt;version&gt;3.2.3&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;com.github.hypfvieh&lt;/groupId&gt; &lt;artifactId&gt;bluez-dbus&lt;/artifactId&gt;
    &lt;version&gt;0.1.3&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;com.rm5248&lt;/groupId&gt;
    &lt;artifactId&gt;dbus-java-nativefd&lt;/artifactId&gt;
    &lt;version&gt;1.0&lt;/version&gt;
&lt;/dependency&gt;
…

Those were added so that I could then define each one of my four module-info.java descriptors to be pretty much exactly like yours…

module get.pid{
    exports getpid;
    requires dbus.java;
    requires dbus.java.nativefd;
    requires bluez.dbus;
    requires jnr.ffi;
    requires jffi;
    requires jnr.x86asm;
    requires jnr.posix;
    requires jnr.enxio;
    requires jnr.unixsocket;
    requires jnr.constants;
    requires jnr.a64asm;
}

Before I did the --patch-module, I ran one of the example projects and got the exact same error you got.

But with the following command, all the example applications ran perfectly fine as modules…

java --patch-module jffi={{your.own.location}}/com/github/jnr/jffi/1.3.0/jffi-1.3.0-native.jar --add-modules org.objectweb.asm --add-exports org.objectweb.asm/org.objectweb.asm=jnr.ffi --add-exports org.objectweb.asm/org.objectweb.asm.signature=jnr.ffi --module-path {{path.to.all.the.jars}} -m get.pid/getpid.Getpid

The add-modules and add-exports are crucial too. So don't leave those out.

huangapple
  • 本文由 发表于 2020年9月17日 16:39:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63934326.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定