I have a simple Spring Boot project which loads native libraries. The problem is that I have no idea how to specify the path to the native library when running the application.
I have read tons of posts explaining how to set java.library.path
but every single one leads to
java.lang.UnsatisfiedLinkError: /path/to/lib/libconnector.so: libconnector.so: cannot open shared object file: No such file or directory
The project works if I run these two commands in a sequence from command line:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/lib
./gradlew bootRun
The library is loaded and works. But I am unable to specify the library path in my gradle file. I tried
run {
systemProperty 'java.library.path', file('/path/to/lib')
}
bootRun {
systemProperty 'java.library.path', file('/path/to/lib')
}
and all sorts of variations of this. Also tried adding VM arguments to my IDE etc. but nothing works. Could someone explain what am I doing wrong?
This is how I load the native library (located in $projectRoot/lib
):
static {
// load connector library
File lib = new File("lib/" + System.mapLibraryName("connector"));
System.load(lib.getAbsolutePath());
}