How to add OS native libraries to java.library.path for testing?


(sean.hyrich) #1

I’m working on a project that uses sqlite4java. In addition to the main jar, it also has native libraries (*.so, *.dll). When I run a build on my project and gradle executes my unit tests, I get the following UnsatisfiedLinkError:

com.almworks.sqlite4java.SQLiteException: [-91] cannot load library: java.lang.UnsatisfiedLinkError: no sqlite4java-linux-i386-0.282 in java.library.path
 at com.almworks.sqlite4java.SQLite.loadLibrary(SQLite.java:97)
        ...

My current build.gradle file looks like this:

apply plugin: 'java'
apply plugin: 'idea'
  repositories {
    mavenCentral()
}
  dependencies {
    compile 'org.apache.commons:commons-lang3:3.1'
    compile 'com.almworks.sqlite4java:sqlite4java:0.282'
      testCompile 'junit:junit:4.10'
    testCompile 'org.easymock:easymock:3.1'
      testRuntime group: 'com.almworks.sqlite4java', name: 'libsqlite4java-linux-i386', version: '0.282', ext: 'so'
}

I’m sure this is probably as easy fix, I just haven’t found any examples on how this kind of thing is done.


(Peter Niederwieser) #2

You can set the ‘java.library.path’ system property like so:

tasks.withType(Test) {
    systemProperty "java.library.path", "/some/path"
}

Anything other than that shouldn’t be specific to Gradle.


(sean.hyrich) #3

Thanks for the prompt reply, Peter.

That definitely works. I’m just fighting with sqlite4java specific issues now, for some reason it’s still not able to find the native .so library even though it’s definitely in the location specified by the java.library.path property.


(sean.hyrich) #4

Well… somewhere along the way I managed to rename the native sqlite4java library from libsqlite4java-linux-i386.so to sqlite4java-linux-i386.so, so the problem was starring me in the face the whole time…

Thanks again for getting me pointed in the right direction.


(David Laurell) #5

Pneumee, how did you get the path to the sqlite4java-linux-i386.so file using the snippet from Peter Niederwieser?


(sean.hyrich) #6

Hey David,

Unfortunately, I’ve since left the job where I was working on that project and haven’t touched gradle for over a year. Wish I could be of more help on this one. Hope you’re able to figure things out.

Sean