I'm trying to work out if there is a definitive, recommended, robust way to work with native libraries in Java and Maven.
I know it's possible to do this by putting libraries in the right places, configuring java.library.path
and calling System.loadLibrary
etc. - but I want a proper solution that works across the whole development / deployment life-cycle and doesn't involve lots of hacks.
My requirements seem fairly straightforward:
.jar
that doesn't require the user to fiddle with command line options to run it (ie it will unpack and load any native dependencies it needs at runtime, preferably as temp files or something like that) Basically, I want natives to just work both during development and for the user at runtime.
Is this possible? If so what do I need to configure to make it happen?
It certainly is possible. A good example that I came across which solves the same problem is sqlite wrapper at https://bitbucket.org/xerial/sqlite-jdbc/overview
By following a pre defined packaging structure for each architecture, we can programmatically extract the desired native library from class path into a temp folder and can set the desired java.library.path to load the native library.
I have not personally tried executing the above flow but could not think of any other way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.