I am trying to create a header file using javah tool from the command line and an external tool configuration on eclipse on windows 7 OS but it's not working.
My code is:
package mypackage;
public class HelloWorld {
private static String HelloWorld;
private native void print();
static {
System.loadLibrary(HelloWorld);
}
public static void main(String[] args)
{
new HelloWorld().print();
}
}
I have followed different ways and even read the documentation of javah tool from Oracle, but they didn't help to overcome this problem.
My class file (HelloWorld.class) and java file (HelloWorld.java) both are in C:\..\eclipse-workspace\Distribution System Process\src\mypackage
But whenever I run javah tool, it gives me an error:
could not find class file for HelloWorld or mypackage.HelloWorld
I tried by providing classpath as well, but am not getting any header file.
Note: I have two classes in my package. The Frame1.java is the main class, which is the Gui, and the other class is used for JNI and called HelloWorld.java. I am not sure if the classes matter, but I am currently working on HelloWorld.java to create a header file:
What is causing this failure? :(
javah
tool requres access to compiled code. You have to provide place, where your compiled class is.Take a look here for a very simple sample code:
http://jnicookbook.owsiak.org/recipe-No-001/
As you can see, sources are compiled and stored inside some other place (here it is called
target
)Then, you have to tell
javah
where to find these files (compiledJava
classes). It is done by-cp
argument.Argument
-d
, on the other hand, will telljavah
where to storeC
headers.