3 ms·
> Java didn’t have any shared library concerns It definitely does have such concerns, but the community has just accepted that the JDK will never help with thi
by mike_hearn 3y ago
> Java didn’t have any shared library concerns
It definitely does have such concerns, but the community has just accepted that the JDK will never help with this and so every JAR that uses a native library hacks around the lack of proper support in its own unique and special way. Usually some project-specific ad-hoc code that extracts native libraries into some directory in the user's home directory.
Is the "cache" versioned properly? Maybe.
Can you control where it is? Maybe.
Code signing? Probably not.
Can you ship only native code for the machines you actually care about? Maybe.
Does it work when you run as a dedicated server UNIX users that doesn't have a home directory? Nope.
Hydraulic Conveyor (https://hydraulic.dev/ https://hydraulic.dev/ - disclosure, my company) fixes a lot of these problems automatically. But it's not like there are no problems to fix, and of course writing a library that uses native code is still a big pain. It's a major blind spot of the JDK unfortunately, and the community has never risen to the challenge of fixing it.
- mwcampbell 3y agoI'm currently working on Java bindings for my own native library. (I'd like to use the Panama FFM API, but unfortunately, my first user is stuck on JDK 11 for now, so I'm stuck with JNI.) Do you have any recommendations on how I should handle the packaging and library loading problem, so I don't make things worse for Conveyor (though my first user isn't using that)? Any reference implementation that I should look at and copy?
- mike_hearn 3y agoIt just means being compatible with library extraction: https://conveyor.hydraulic.dev/10.1/configs/jvm/#native-code https://conveyor.hydraulic.dev/10.1/configs/jvm/#native-code So it's really easy. Just run System.loadLibrary("foo") before doing anything else. On developer setups that line will throw because the JVM won't find the shared library, so then you can go down the road of extracting things to the homedir or whatever else you want to do (or do it manually and check in the results). Deployed installs will find the library in the right platform specific directories inside the app package and pass.