I’ve a rust library that I want to call from Java.
I’ve managed to create the corresponding .h-file and extract from that the Java bindings.
As long as my project structure looks like the following, I can access the c-function when compiling and starting the program with
javac --source=22 -d . src/my/panama/java/project/name/*.java
java --enable-native-access=ALL-UNNAMED Main.java
├── Cargo.lock
├── Cargo.toml
├── Main.java
├── my
│ └── panama
│ └── java
│ └── project
│ └── name
│ ├── projectPanamaFiles.class
├── libmy_rust.dylib
├── my_rust_lib.h
└── src
├── my
│ └── panama
│ └── java
│ └── project
│ └── name
│ ├── projectPanamaFiles.java
├── lib.rs
└── custom_functions.rs
Now I want to integrate the native library to my main project (Micronaut 4.4.2 & Java 22) with a structure looking like:
── src
└── main
├── java
│ └── my
│ └── panama
│ └── java
│ └── project
│ └── name
│ └── Application.java
└── rust
├── same As above
When I place all of the .class files of the Panama binding in src/main/java/my/Panama/java/project/name/library
, I can use them in IntelliJ as every other library.
When I try to run my app, it fails with java.lang.IllegalArgumentException: Cannot open library: libprocess_dlms.dylib
.
I’ve tried adding it via gradle.kts via implementation(fileTree("src/main/rust"))
but nothing changed.
Also adding it directly via System.load("/absolute/path/to/libmy_rust.dylib");
results in the same error message.