Hacker News new | past | comments | ask | show | jobs | submit

How to Use the Foreign Function API in Java 22 to Call C Libraries

https://ifesunmola.com/how-to-use-the-foreign-function-api-in-java-22-to-call-c-libraries/
loading story #40301793
What I'm missing is a model for building/distributing those C libraries with a java application.

Every ffi example I've found seem to operate on the assumption that you want to invoke syscalls or libc, which (with possibly the exception of like madvise and aioring) Java already mostly has decent facilities to interact with even without native calls.

Native libraries are typically packaged inside a jar so that everything works over the existing build and dependency management systems.

For example, each these jars named "native-$os-$arch.jar" contain a .dll/.so/.dylib: https://repo1.maven.org/maven2/com/aayushatharva/brotli4j/

JNA will extract the appropriate native library (using os.name and os.arch system properties), save the library to a temp file, then load it.

    > JNA will extract the appropriate native library ..., save the library to a temp file, then load it.
JNA does this?

FYI: JNA = Java Native Access project: https://github.com/java-native-access/jna

loading story #40305045
Examples of JARs, that transport such libraries: snappy, sqlite...
loading story #40301718
loading story #40300722
loading story #40303594
loading story #40309437
loading story #40300693
loading story #40300675
loading story #40306125
loading story #40301315
loading story #40300948
loading story #40302356
loading story #40301525
loading story #40306428
loading story #40305467
loading story #40301312
loading story #40300285
loading story #40305259
loading story #40303018