I've currently got a Java application that is dynamically loading in a native library on two different platforms, Windows and Linux. I have the same library built targeting these two systems, a library.dll and a liblibrary.so.
I've got to send this thing out to customers so I've got IntelliJ packaging up .msi and .deb artifacts. Now, rather than also send these packages along with the respective dynamic libraries and instructing the customers to drop them in their windows/system32 and /usr/lib/ directories, I'd much prefer that this is all taken care of behind the scenes. I imagine there is some way to package up the dynamic library into my .msi or .deb and instruct these installers to copy the library to the correct folder, but I worry about permission errors and things like that.
I've read that Java 1.8 now supports static libraries but there appears to be a shocking lack of documentation of just how you're supposed to accomplish this. Everyone agrees that you need to expose two new calls in your library, JNI_OnLoad_LibraryName
and JNI_OnUnload_LibraryName
and you just call System.loadLibrary("libraryName")
the same as usual. However, no one appears to mention or at the very least give instructions on how you're supposed to package up your static library along with the JVM.
The Java documentation on the addition of this feature simply states:
A native JVMTI Agent may be statically linked with the VM. The manner in which the library and VM image are combined is implementation-dependent.
Am I just not searching for the right terms to find out how to package a static native library into the JVM? Should I even be bothering with static libraries? Is there some easier solution I'm missing?