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.


Solution 1:

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

Solution 2:

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

Solution 3:

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...