Command:
javah -jni JavaHowTo
Result:
error: cannot access JavaHowTo
class file for JavaHowTo not found
javadoc: error -
I had this problem when I add to -classpath my source directory. I thought classes are in *.java files ;)
Javah is working on byte code so you have to add directory with your binaries to classpath
I made some eclipse task:
"Location"
${env_var:JAVA_HOME}\bin\javah.exe
"Arguments"
-verbose
-force
-classpath ;${project_loc}\bin
-d ${project_loc}\jni
${java_type_name}
Select file and Run
javah
does not work properly from Cygwin terminal:
$ cd /cygdrive/c/Workspace/prj/bin
$ ls com/example/JavaHotTo.class
com/example/JavaHotTo.class
$ javah com.example.JavaHowTo
Error: Could not find class file for 'com.example.JavaHowTo'.
But it works perfectly using the option -classpath .
$ javah -classpath . com.example.JavaHowTo
$ ls *.h
com_example_JavaHotTo.h
More tricks:
-jni
is by default, therefore it is not require.classpath
javah
on MS-Windows prefers path à la C:\Workspace\prj\bin
cygpath -w /cygdrive/c/Workspace/prj/bin
to convert into MS-Windows format-d your/jni/headers/path
to write headers in another directoryjavah
creates the path your/jni/headers/path
if it does not exist (see below)
$ javah -d jni/headers -classpath . com.example.JavaHowTo
$ ls jni\headers
com_example_JavaHotTo.h
$ javah -d jni\path -classpath . com.example.JavaHowTo
$ ls jni\path
com_example_JavaHotTo.h
In my case the problem was pretty stupid.. I try: javah com.aaa.bbb.ClassName.class
without ".class" I generate the .h file correctly
javah com.aaa.bbb.ClassName
Following worked for me... Go to project path from terminal like,
/home/usr/Desktop/Workspace/ProjectName/src/main/java
and hit following command,
javah -jni com.abc.test.callfileName (Without .class extension)
com_abc_test_className.h file will get created in following path /home/usr/Desktop/Workspace/ProjectName/src/main/java
finally the command looks like, [my-machine/usr] $ /home/usr/Desktop/Workspace/ProjectName/src/main/java/src/main/java>javah -jni com.abc.test.className
For Windows...
javaFileName: HelloWorld.java
packageCode: "package com.accessibility;"
importCode: "import com.accessibility.HelloWorld;"
javaFileLocation: "S:\Accessibility\tools\src\test\java\com\accessibility\HelloWorld.java"
The javaFileLocation should be viewed as having two parts...
classpath: "S:\Accessibility\tools\src\test\java"
relativeFilePath: "com\accessibility\HelloWorld.java"
The second line below was run from the Windows Command Prompt.
{javacLocation} -d {ouputDirectory} {javaFileLocation}
"C:\Program Files\Java\jdk1.6.0_26\bin\javac.exe" -d "S:\Accessibility\tools\src\test\java" "S:\Accessibility\tools\src\test\java\com\accessibility\HelloWorld.java"
This created the HelloWorld.class file
classFileName: HelloWorld.class
classFileLocation: "S:\Accessibility\tools\src\test\java\com\accessibility\HelloWorld.class"
The second line below was run from the Windows Command Prompt.
{javahLocation} -o {outputFile} -classpath {classpath} {importName}
"C:\Program Files\Java\jdk1.6.0_26\bin\javah.exe" -o "S:\Accessibility\tools\src\test\java\com\accessibility\HelloWorld.h" -classpath "S:\Accessibility\tools\src\test\java" com.accessibility.HelloWorld
This created the HelloWorld.h file
classFileName: HelloWorld.h
classFileLocation: "S:\Accessibility\tools\src\test\java\com\accessibility\HelloWorld.h"
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