I'm new in Java learning and first time want to get start JNI. And I am working with Cygwin and I have created a file with .java (Helloworld.java) extension as follows:
class HelloWorld {
private native void print();
public static void main(String[] args) {
new HelloWorld().print();
}
static {
System.loadLibrary("HelloWorld");
}
}
Then I compile the file through the command line (javac Helloworld.java
) after that create a native header file through command javah –jni Helloworld
Then also implement by creating a C file as:
#include <jni.h>
#include <stdio.h>
#include "HelloWorld.h"
JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
printf("Hello World!\n");
return;
}
After that while I run the command
Gcc –wall –g Helloworld.c –o hello
Give the message in command prompt line in Cygwin
helloworld.c:1:17: fatal error: jni.h: No such file or directory
compilation terminated.
How to run and what is the procedure to set the path to execute the file? Please help me any one. Thanks.
I guess you haven't added the jni directory to the include directory list, check http://social.msdn.microsoft.com/forums/is/vclanguage/thread/cd7f2d1d-f750-494c-a3b2-7d4186cfe51c for details.