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

**URL:** <https://discuss.gradle.org/t/how-to-add-os-native-libraries-to-java-library-path-for-testing/6501>\
**Category:** Old Forum Archive\
**Created:** [September 26, 2012, 10:31pm UTC](https://discuss.gradle.org/t/how-to-add-os-native-libraries-to-java-library-path-for-testing/6501 "2012-09-26T22:31:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pneumee](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/pneumee/32/1119_2.png) [@pneumee](https://discuss.gradle.org/u/pneumee)\
**Post date:** [September 26, 2012, 10:31pm UTC](https://discuss.gradle.org/t/how-to-add-os-native-libraries-to-java-library-path-for-testing/6501/1 "2012-09-26T22:31:00Z")

</div>

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:

```gradle
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:

```gradle
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.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [September 27, 2012, 5:10am UTC](https://discuss.gradle.org/t/how-to-add-os-native-libraries-to-java-library-path-for-testing/6501/2 "2012-09-27T05:10:00Z")

</div>

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

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

```

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

---

<div class="post-metadata">

**Author:** ![pneumee](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/pneumee/32/1119_2.png) [@pneumee](https://discuss.gradle.org/u/pneumee)\
**Post date:** [September 28, 2012, 9:12pm UTC](https://discuss.gradle.org/t/how-to-add-os-native-libraries-to-java-library-path-for-testing/6501/3 "2012-09-28T21:12:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pneumee](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/pneumee/32/1119_2.png) [@pneumee](https://discuss.gradle.org/u/pneumee)\
**Post date:** [September 28, 2012, 11:29pm UTC](https://discuss.gradle.org/t/how-to-add-os-native-libraries-to-java-library-path-for-testing/6501/4 "2012-09-28T23:29:00Z")

</div>

Well… somewhere along the way I managed to rename the native sqlite4java library from [libsqlite4java-linux-i386.so](http://libsqlite4java-linux-i386.so) to [sqlite4java-linux-i386.so](http://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.

---

<div class="post-metadata">

**Author:** ![david\_laurell](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/david_laurell/32/1420_2.png) [@david\_laurell](https://discuss.gradle.org/u/david_laurell)\
**Post date:** [March 30, 2014, 1:25pm UTC](https://discuss.gradle.org/t/how-to-add-os-native-libraries-to-java-library-path-for-testing/6501/5 "2014-03-30T13:25:00Z")

</div>

Pneumee, how did you get the path to the [sqlite4java-linux-i386.so](http://sqlite4java-linux-i386.so) file using the snippet from Peter Niederwieser?

---

<div class="post-metadata">

**Author:** ![pneumee](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/pneumee/32/1119_2.png) [@pneumee](https://discuss.gradle.org/u/pneumee)\
**Post date:** [April 1, 2014, 4:19pm UTC](https://discuss.gradle.org/t/how-to-add-os-native-libraries-to-java-library-path-for-testing/6501/6 "2014-04-01T16:19:00Z")

</div>

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
