I was learning JNI which uses libraries, and the tuturial is https://www.baeldung.com/jni. The java source file is
package zxy;
public class JNIDemo {
public native void testHello();
public static void main(String[] args){
System.loadLibrary("native");
JNIDemo jniDemo = new JNIDemo();
jniDemo.testHello();
System.out.println("zxy");
}
}
and the project directory is:
/src/main/java/zxy
|->JNIDemo.java
/libs
|-> libnative.so
build.gradle
gradlew
settings.gradle
the build.gradle file is
plugins {
id 'application'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
application {
mainClass = 'zxy.JNIDemo'
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation files('libs/libnative.so')
}
and the settings.gradle is
rootProject.name = 'jni'
When I run ./gradlew installDist
, it works fine,
and gives my the following dir structure
build/
|-> /install/jni
|-> /bin
|-> jni
|-> jni.bat
|-> /lib
|-> jni-1.0-SNAPSHOT.jar
|-> libnative.so
But when I run build/install/jni/bin/jni
, I gives me
Exception in thread "main" java.lang.UnsatisfiedLinkError: no native in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
at java.lang.Runtime.loadLibrary0(Runtime.java:871)
at java.lang.System.loadLibrary(System.java:1124)
at zxy.JNIDemo.main(JNIDemo.java:8)
FAILURE: Build failed with an exception.
I dont understand why, how can I include java.library.path in command gradlew installDist