Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javah command for native methods gives Exception [closed]

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.

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)
like image 802
Sarah Szabo Avatar asked Feb 10 '13 05:02

Sarah Szabo


People also ask

What is javah command?

Description. The javah command generates C header and source files that are needed to implement native methods. The generated header and source files are used by C programs to reference an object's instance variables from native source code.

What is native method in Java?

Native methods are Java™ methods that start in a language other than Java. Native methods can access system-specific functions and APIs that are not available directly in Java. The use of native methods limits the portability of an application, because it involves system-specific code.


1 Answers

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.

Class name should not include .class extension.

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

Also you should follow Java naming conventions and make your package names lower case.

like image 138
Oleg Mikheev Avatar answered Oct 15 '22 22:10

Oleg Mikheev