I have seen many examples for a JNI application. I have tried one myself and getting an exception
dileepvikram@dileepvikram-System-Product-Name:~/include$ java -Djava.Library.path=. Test
Exception in thread "main" java.lang.UnsatisfiedLinkError: no Test in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1738)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at Test.<clinit>(Test.java:9)
Could not find the main class: Test. Program will exit.
Test.java
public class Test {
public native void sayHello(int length) ;
public static void main (String args[]) {
String str = "I am a good boy" ;
Test h = new Test () ;
h.sayHello (str.length() ) ;
}
static {
System.loadLibrary ( "Test" ) ;
}
}
I have compiled he code and created a Test.h with the code
javah -jni Test
Test.c
#include "Hello.h"
#include<stdio.h>
#include "jni.h"
JNIEXPORT void JNICALL Java_hello_sayHello
(JNIEnv *env, jobject object, jint len) {
printf ( "\nLength is %d", len ); }
void main()
{
printf("\nHello World\n");
}
Then I have compiled the c code with the command
gcc Test.c -o libTest.so
and then tried running the java class with the command
java -Djava.library.path=. Test
And I am getting the exception
dileepvikram@dileepvikram-System-Product-Name:~/include$ java -Djava.Library.path=. Test
Exception in thread "main" java.lang.UnsatisfiedLinkError: no Test in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1738)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at Test.<clinit>(Test.java:9)
Could not find the main class: Test. Program will exit.
I have tried a lot ,to find the issue,any help is appreciated.