17

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)
Sarah Szabo
  • 10,345
  • 9
  • 37
  • 60
  • 6
    Viewed 10,594 times, please open this question! – User3 Dec 28 '17 at 14:58
  • I am having this problem javah -jni -classpath "\home\npsdk\niagara_dev_home\sampl es\npsdkJni\npsdkJni-rt\src\" -d "\home\npsdk\niagara_dev_home\samples\npsdkJni\npsdkJni-rt\src\native\npsdk\include\jni\" com.tridium.nre.NreLinuxNpsdk0 Error: Could not find class file for 'com.tridium.nre.NreLinuxNpsdk0'. – prem30488 Oct 16 '18 at 05:38

1 Answers1

16

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.

Oleg Mikheev
  • 17,186
  • 14
  • 73
  • 95
  • 9
    Confused about the reason why this thread is closed, I'm the "future visitors" and I got help from this thread. ^_^ – Eugene Dec 05 '17 at 02:19