Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javah error while using it in JNI

Command:

javah -jni JavaHowTo

Result:

error: cannot access JavaHowTo 
class file for JavaHowTo not found

javadoc: error - Class JavaHowTo not found.
Error: No classes were specified on the command line.  Try -help.

I have set the class path correctly, but still i am getting this javah error.

Any solution for this will be much helpful.

like image 472
krishnakumar Avatar asked Jun 12 '09 11:06

krishnakumar


4 Answers

Try

javah -jni com.example.JavaHowTo

where com.example is your package.

You also need to run javah from the directory containing com/example/JavaHowTo.class

e.g. if your structure is

/home/user/com/example/JavaHowTo.class

run javah from

/home/user
like image 65
Glen Avatar answered Nov 15 '22 11:11

Glen


The following worked for me (Win7):

javah -classpath bin/classes -jni -d jni com.my.javaclass

I run this from the app main directory.

The problem was in the sub-directory classes

like image 38
jankos Avatar answered Nov 15 '22 12:11

jankos


I successfully use javah every day from my build scripts with the following options:

javah -d <outputdir> -classpath <classpath> <fully_qualified_class>

where:

'outputdir' is the directory where to put the generated header file

'classpath' contains an absolute path to the directory containing your root package (as mentionned by Glen)

'fully_qualified_class' is the name of the class containing native methods without .class extension

-jni option is not required (set by default)

Anyway you should check your class file has been generated: quite surprised you get a javadoc error too...

like image 43
dilig0 Avatar answered Nov 15 '22 11:11

dilig0


I encountered the same error and using http://www.inonit.com/cygwin/jni/helloWorld/header.html link I was able to successfully generate the .h file. I used the following command

C:\Program Files\Java\jdk1.6.0_21\bin>javah -d C:\Prachi\Android\Workspace_QP_re
structure\HelloWorld\bin\example\jni -classpath C:\Prachi\Android\Workspace_QP_r
estructure\HelloWorld\bin example.jni.HelloWorld

here example.jni is my package name and C:\Prachi\Android\Workspace_QP_re structure\ is where my eclipse workspace path.

Hope this helps you

like image 9
Prachi Shrivastava Avatar answered Nov 15 '22 11:11

Prachi Shrivastava