I have generated a dll file with jni using command prompt. I can run the code below with "java helloWorld" command. But I can't do it from eclipse. When I ran the program I get an error, that says:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no native_library in java.library.path at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown Source) at java.lang.System.loadLibrary(Unknown Source) at helloWorld.(helloWorld.java:6)
I have used absolute path for native_library as you can see below. What's the problem with it?
helloWorld.java:
public class helloWorld {
static{
System.loadLibrary("native_library");
System.load("C:/javaworkspace/helloWorld/src/native_library.dll");
}
public static native void writeout(String ss);
public static void main(String[] args) {
String sdf="Hello World";
writeout(sdf);
}
}
native_library.c:
#include <stdio.h>
#include "helloWorld.h"
JNIEXPORT void JNICALL Java_helloWorld_writeout
(JNIEnv * env, jclass clazz, jstring str2)
{
const char *nativeString = (*env)->GetStringUTFChars(env, str2, 0);
printf("%s \n",nativeString);
(*env)->ReleaseStringUTFChars(env, str2, nativeString);
}