简体   繁体   English

javah -jni<classname> 不工作?

[英]javah -jni <classname> not working?

I've been trying to create a .h file with the command :我一直在尝试使用以下命令创建 .h 文件:

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:但是,每当我执行javah -jni命令时,都会出现以下错误:

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顺便说一下,我正在使用 Windows 10 PC

Take a look at package defined inside MyClass.看一下 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.确保该类可通过 CLASSPATH 获得。

Alternatively, you can pass class location (together with package) via -cp argument for javah.或者,您可以通过 javah 的 -cp 参数传递类位置(连同包)。

Take a look here:看看这里:

http://jnicookbook.owsiak.org/recipe-No-001/ 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如果它适合您,请确保使用您在 Makefile 中可以找到的类似编译标志

Have fun with JNI :)玩得开心 JNI :)

Update:更新:

As already pointed out in comments above, maybe you can switch to Oracle's JDK?正如上面评论中已经指出的那样,也许您可​​以切换到 Oracle 的 JDK?

If you use Oracle's JDK there are no issues of that sort.如果您使用 Oracle 的 JDK,则不会出现此类问题。 You can easily generate C header using javah您可以使用 javah 轻松生成 C 头文件

In case you have to stick to GCJ (eg legacy code), maybe give it a try with如果您必须坚持使用 GCJ(例如遗留代码),不妨尝试一下

javah -jni -cp . Main

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM