java 本机方法的 Javah 命令给出异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14795050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javah command for native methods gives Exception
提问by Sarah Szabo
I entered this into command prompt and I'm not sure why it is saying that it is not a valid class name considering that it has the position on the disk and the fully qualified class name. Java - version works and I'm running the latest version of the JVM with the JDK, also the CLASSPATH is configured properly.
我将其输入到命令提示符中,但我不确定为什么会说它不是有效的类名,因为它在磁盘上具有位置和完全限定的类名。Java - 版本有效,我正在使用 JDK 运行最新版本的 JVM,并且 CLASSPATH 配置正确。
The class is this:
班级是这样的:
package JNI;
public class Main {
public native void printTitle();
public static void main(String[] args) {
Main main = new Main();
main.print();
}
public void print(){
System.out.println("The print subroutine has finished.");
}
And the command line args are:
命令行参数是:
C:\Users\USER\Documents\NetBeansProjects\JNI Test Project\build\classes\JNI>javah -jni -classpath "C:\Users\USER\Documents\NetBeansProjects\JNI Test Project\build\classes\JNI" JNI.Main.class
Exception in thread "main" java.lang.IllegalArgumentException: Not a valid class name: JNI.Main.class
at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:177)
at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:68)
at com.sun.tools.javah.JavahTask.run(JavahTask.java:509)
at com.sun.tools.javah.JavahTask.run(JavahTask.java:335)
at com.sun.tools.javah.Main.main(Main.java:46)
采纳答案by Oleg Mikheev
classpath
should point to the root folder where your top level package (JNI) goes to, not to the folder where your class is physically located.
classpath
应该指向您的顶级包 (JNI) 所在的根文件夹,而不是您的类所在的文件夹。
Class name should not include .class
extension.
类名不应包含.class
扩展名。
Think about it as operating on classes and not physical files.
将其视为对类而不是物理文件的操作。
javah -jni -classpath "C:\Users\GETH COMMANDER\Documents\NetBeansProjects\JNI Test Project\build\classes" JNI.Main
javah -jni -classpath "C:\Users\GETH COMMANDER\Documents\NetBeansProjects\JNI Test Project\build\classes" JNI.Main
Also you should follow Java naming conventions and make your package names lower case.
此外,您应该遵循 Java 命名约定并使您的包名称小写。