Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javah tool error: Could not find class file for hellojni

I am trying to create a header file using javah tool from command line on windows 7 OS but i am failing all the time.

I have followed different ways and even read the documentation of javah tool from oracle but they didn't help to overcome with this problem.

My class file (hellojni.class) and java file (hellojni.java) both are in the root of D:\ drive.

But whenever I run javah tool it gives me an error:

could not find class file for hellojni

I tried by providing classpath as well but not getting any header file.

like image 243
S.S Sahota Avatar asked Oct 02 '13 12:10

S.S Sahota


1 Answers

I suspect the issue is that your class has a package and you are trying to run the command from the directory with the class file instead of the package root.

Samhain's example works because his MyClass.java contains no package, whereas I suspect yours does.

For example, assume we have the following file at c:\src\com\example\MyClass.java

package com.example;  public class MyClass {     public native void myMethod(); } 

Go to the command line and execute the following:

c:\src\com\example>javac MyClass.java  c:\src\com\example>dir   Directory of C:\src\com\example  2015-02-23  03:17 PM    <DIR>          . 2015-02-23  03:17 PM    <DIR>          .. 2015-02-23  03:20 PM               219 MyClass.class 2015-02-23  03:17 PM                84 MyClass.java  c:\src\com\example>javah MyClass Error: Could not find class file for 'MyClass'.  c:\src\com\example>cd c:\src  c:\src>javah com.example.MyClass  c:\src>dir  Directory of C:\src  2015-02-23  03:18 PM    <DIR>          . 2015-02-23  03:18 PM    <DIR>          .. 2015-02-23  03:16 PM    <DIR>          com 2015-02-23  03:18 PM               449 com_example_MyClass.h 

Success!

like image 198
hendalst Avatar answered Sep 20 '22 03:09

hendalst