Reputation: 609
I've been trying to create a .h file with the command :
javah -jni MyClass
of course after doing
javac MyClass.java
which doesn't give me any error messages...
However whenever I execute the javah -jni
command I get the following error:
Exception in thread "main" java.io.IOException: can't find class file
MyClass.class in
java.net.URLClassLoader{urls=[file:/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre/lib/rt.jar],
parent=gnu.gcj.runtime.SystemClassLoader{urls=[file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}}
at gnu.classpath.tools.javah.Main.getClass(libgcj-tools.so.14)
at gnu.classpath.tools.javah.Main.parseClasses(libgcj-tools.so.14)
at gnu.classpath.tools.javah.Main.run(libgcj-tools.so.14)
at gnu.classpath.tools.javah.Main.main(libgcj-tools.so.14)
By the way I'm working on a Windows 10 PC
Upvotes: 0
Views: 705
Reputation: 13385
Take a look at package defined inside MyClass. It might be that you are using some package name and then you are passing just class name - this will not work.
Make sure that class is available via CLASSPATH.
Alternatively, you can pass class location (together with package) via -cp argument for javah.
Take a look here:
http://jnicookbook.owsiak.org/recipe-No-001/
You can find there fully working, supper simple sample.
It should work out of the box. Just do:
git clone https://github.com/mkowsiak/jnicookbook.git
cd jnicookbook/recipes/recipeNo001
make; make test
If you still have issues here. It might be there is something not quite ok with your installation.
If it works for you, just make sure to use similar compilation flags as you can find inside Makefile
Have fun with JNI :)
Update:
As already pointed out in comments above, maybe you can switch to Oracle's JDK?
If you use Oracle's JDK there are no issues of that sort. You can easily generate C header using javah
In case you have to stick to GCJ (e.g. legacy code), maybe give it a try with
javah -jni -cp . Main
Upvotes: 0