A proof of concept for consuming native libraries (specifically: a Rust one) from a Spigot Java plugin.
Please note that this project requires exactly Java 16. Java 17 removed the ability to lookup a symbol in a specific library. To learn more, see this Jira issue and this commit.
Tested with OpenJDK 16.0.1, x64 Windows, stable Rust & MSVC toolchain.
-
Build the Java plugin with
mvn package
. Throw the resulting.jar
into your server's/plugins
directory. -
Start your server with foreign access features enabled. This should create a
plugins-native
folder in your server's root.Example command:
java -D"foreign.restricted"="permit" --add-modules=jdk.incubator.foreign -jar paper.jar -nogui
-
Build the Rust library with
cargo build --release
. Put theplugin_native
.dll/.so in the previously created/plugins-native
folder. -
Run the Spigot server again. You should be able to see a
[PluginBridge] Hello from Rust, world!
log message in your terminal.