2

I'm working on a small gradle based javafx project using netbeans ide (win7). Everything works fine until i included cloudant-sync and sqlite4java, now i get UnsatisfiedLinkError whenever i run the project. Please how do i resolve this.

java.lang.UnsatisfiedLinkError: no sqlite4java-win32-x64-1.0.392 in java.library.path

See gradle.build and console output below:

gradle.build

apply plugin: 'java'

sourceCompatibility = '1.8' [compileJava, compileTestJava].options.encoding = 'UTF-8'

// NetBeans will automatically add "run" and "debug" tasks relying on the // "mainClass" property. You may however define the property prior executing // tasks by passing a "-PmainClass=" argument. // // Note however, that you may define your own "run" and "debug" task if you // prefer. In this case NetBeans will not add these tasks but you may rely on // your own implementation. if (!hasProperty('mainClass')) { ext.mainClass = 'falcon3.Main' }

repositories { mavenCentral() }

dependencies { compile 'com.jfoenix:jfoenix:1.1.0' compile group: 'com.cloudant', name: 'cloudant-sync-datastore-javase', version:'2.0.0' compile group: 'com.almworks.sqlite4java', name: 'sqlite4java', version: '1.0.392' compile 'com.aquafx-project:aquafx:0.2' testCompile group: 'junit', name: 'junit', version: '4.10' }

and

console output

Executing: gradle run Arguments: [-c, C:\Users\???\Documents\NetBeansProjects\Falcon3\settings.gradle]

:compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE Feb 11, 2017 11:57:23 AM com.almworks.sqlite4java.Internal log INFO: [sqlite] DB[1]: instantiated [null] Exception in Application start method java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.ExceptionInInitializerError at com.cloudant.sync.internal.sqlite.SQLDatabaseQueue.(SQLDatabaseQueue.java:67) at com.cloudant.sync.internal.documentstore.DatabaseImpl.(DatabaseImpl.java:152) at com.cloudant.sync.documentstore.DocumentStore.(DocumentStore.java:90) at com.cloudant.sync.documentstore.DocumentStore.getInstance(DocumentStore.java:150) at com.cloudant.sync.documentstore.DocumentStore.getInstance(DocumentStore.java:120) at falcon3.Main.start(Main.java:28) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191) ... 1 more Caused by: java.lang.IllegalStateException: Failed to open database. at com.cloudant.sync.internal.sqlite.sqlite4java.SQLiteWrapper.createNewConnection(SQLiteWrapper.java:92) at com.cloudant.sync.internal.sqlite.sqlite4java.SQLiteWrapper.getConnection(SQLiteWrapper.java:73) at com.cloudant.sync.internal.sqlite.sqlite4java.SQLiteWrapper.isOpen(SQLiteWrapper.java:121) at com.cloudant.sync.internal.sqlite.sqlite4java.SQLiteWrapper.beginTransaction(SQLiteWrapper.java:126) at com.cloudant.sync.internal.sqlite.SQLDatabaseFactory.isFtsAvailable(SQLDatabaseFactory.java:52) at com.cloudant.sync.internal.sqlite.SQLDatabaseFactory.(SQLDatabaseFactory.java:45) ... 15 more Caused by: com.almworks.sqlite4java.SQLiteException: [-91] cannot load library: java.lang.UnsatisfiedLinkError: no sqlite4java-win32-x64-1.0.392 in java.library.path at com.almworks.sqlite4java.SQLite.loadLibrary(SQLite.java:97) at com.almworks.sqlite4java.SQLiteConnection.open0(SQLiteConnection.java:1441) at com.almworks.sqlite4java.SQLiteConnection.open(SQLiteConnection.java:282) at com.cloudant.sync.internal.sqlite.sqlite4java.SQLiteWrapper.createNewConnection(SQLiteWrapper.java:88) ... 20 more Caused by: java.lang.UnsatisfiedLinkError: no sqlite4java-win32-x64-1.0.392 in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at com.almworks.sqlite4java.Internal.tryLoadFromSystemPath(Internal.java:352) at com.almworks.sqlite4java.Internal.loadLibraryX(Internal.java:124) at com.almworks.sqlite4java.SQLite.loadLibrary(SQLite.java:95) ... 23 more Exception running application falcon3.Main :run FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':run'.

    Process 'command 'C:\Program Files\Java\jdk1.8.0_102\bin\java.exe'' finished with non-zero exit value 1

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.578 secs

Build failure (see the Notifications window for stacktrace): gradle run

Wisdom Ekene
  • 55
  • 1
  • 6

2 Answers2

0

sqlite4java is not a pure Java package, but needs a binary build of the actual SQLite library. This has to be available to the JVM at runtime. The sqlite4java documentation says:

To start using sqlite4java, you only need to place sqlite4java.jar and platform-dependent binaries into a directory in the CLASSPATH. (Binaries should be in the same directory as the jar file.)

Try adding another dependency:

runtime group: 'com.almworks.sqlite4java', name: 'sqlite4java-win32-x64', version: '1.0.392'
Christian
  • 71
  • 1
  • 5
0

This answer helped me: https://stackoverflow.com/a/39086207/3887715

Although the answer is based on DynamoDBLocal, you've already included the sqlite4java dependencies, so you should be able to get it working with a similar set-up.

You need to copy the library files to another directory:

task copyNativeDeps(type: Copy) {
    from(configurations.compile + configurations.testCompile) {
        include '*.dll'
        include '*.dylib'
        include '*.so'
    }
    into 'build/libs'
}

And then set the system property sqlite4java.library.path to the path to that directory. In my case, I needed it for a test, so I just added a initialiser block to my test class:

public class CreateDynamoDBTest {
    {
        System.setProperty("sqlite4java.library.path", "build/libs");
    }

    @Test
    public void test() {

    }
}
Fodder
  • 564
  • 1
  • 10
  • 23