wasmer-java
wasmer-java copied to clipboard
Kotlin: Getting UnsatisfiedLinkError: no wasmer_jni in java.library.path when creating Instance
I am getting following exception with simple example as shown in in this introduction post:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no wasmer_jni in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1124)
at org.wasmer.Instance.<clinit>(Instance.java:17)
at ApplicationKt.main(Application.kt:13)
See following repository: https://github.com/onurhkb/wasm-test
Edit: Using latest version of Intellij
Hello,
What's your platform? How did you install Wasmer JNI (edit: With Gradle as per your repository)?
Thanks.
I see you're using Kotlin. I didn't try with Kotlin yet, but I wouldn't be surprise to see differences between Java and Kotlin here.
Hi, I am on Mac Catalina 10.15.5. Yes, I am using gradle as shown in the example repository. I tried this with Java and got the same problem:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no wasmer_jni in java.library.path: [/Users/<User>/Library/Java/Extensions, /Library/Java/Extensions, /Network/Library/Java/Extensions, /System/Library/Java/Extensions, /usr/lib/java, .]
Did you try Intellij?
I don't use IntelliJ. I'm not familiar with IntelliJ nor Kotlin. I asked help on Twitter, https://twitter.com/mnt_io/status/1295331545771802625.
AFAIK you need to extract your dynamic library to somewhere (usually to some tmp dir) and load it by calling System.load
with a path to the file. You can delegate the task to some library, like:
- https://github.com/adamheinrich/native-utils
- https://github.com/scijava/native-lib-loader
- https://github.com/fusesource/hawtjni
As a workaround, library users could extract a dynamic library themselves and a directory to java.library.path
before calling your API.
The current solution works with Java, but it seems to not work with Kotlin. Is it a difference between the two “languages”?
Our Native
API, https://github.com/wasmerio/java-ext-wasm/blob/master/src/java/org/wasmer/Native.java.
How to use it, https://github.com/wasmerio/java-ext-wasm/blob/master/src/java/org/wasmer/Instance.java#L15-L19.
Maybe something isn't working with Kotlin 🤔, but what?
Could you please share a simple working example in Java?
Honestly, I don't think it's something specific for Kotlin, likely it will not work in a clean environment for any JVM languages, including Java. It could work for somebody because they have required libraries somewhere where JVM searching because a path is part of java.library.path
. If so, an example in other languages should work in the same environment.
You can find a simple example with Kotlin and Java here. Both fail with UnsatisfiedLinkError: no wasmer_jni in java.library.path
.
I’m having the same issue on macOS 10.15.6 (Catalina) with Java 11, when trying to run the examples:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no wasmer_jni in java.library.path: [/Users/<user>/Library/Java/Extensions, /Library/Java/Extensions, /Network/Library/Java/Extensions, /System/Library/Java/Extensions, /usr/lib/java, .]
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2670)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:830)
at java.base/java.lang.System.loadLibrary(System.java:1873)
at org.wasmer.Instance.<clinit>(Instance.java:17)
at SimpleExample.main(SimpleExample.java:10)
make: *** [run-example] Error 1
The examples do work on a Docker container using Debian 10 and Java 11. It seems like it’s OS related.
@bashor what OS did you use for the examples?
@Arash217 I've tried on macOS. How did you run it in Docker?
@bashor Within the Docker container I cloned the wasmer-java repo, manually installed required packages like Java, Gradle, etc. and then ran the examples using 'make run-example EXAMPLE=[name]'. Make sure you install Java 11, newer versions of Java gave me errors.
@bashor after some debugging, I was able to run wasmer-java
from IntelliJ on Mac OS X. I had to add:
-Dos.arch=amd64
To VM Options
under Run/Debug Configurations
for my project.
As far as I can tell there was a recent change that changed wasmer-jni-x86_64-darwin-....jar
to wasmer-jni-amd64-darwin-....jar
, because of this change during startup the linker can't find the right native lib.
Please let me know if this helps.
You can find a simple example with Kotlin and Java here. Both fail with
UnsatisfiedLinkError: no wasmer_jni in java.library.path
.
yes , i failed in java too.
@bashor after some debugging, I was able to run
wasmer-java
from IntelliJ on Mac OS X. I had to add:-Dos.arch=amd64
To
VM Options
underRun/Debug Configurations
for my project.As far as I can tell there was a recent change that changed
wasmer-jni-x86_64-darwin-....jar
towasmer-jni-amd64-darwin-....jar
, because of this change during startup the linker can't find the right native lib.Please let me know if this helps.
thanks very much ! it's work.
oh, it's work ,thanks.