Javah error when used in JNI

Team:

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 set the class path correctly, but still I get this javah error.

Any solution for this would be very helpful.

+42
java classpath jni
Jun 12 '09 at 11:58
source share
14 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

eg. if your structure

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

run javah from

 /home/user 
+79
Jun 12 '09 at 12:05
source share

The following worked for me (Win7):

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

I run this from the main directory of the application.

The problem was in the classes subdirectory

+13
Apr 01 2018-12-12T00:
source share

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

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 is not required (installed by default)

In any case, you should check that your class file has been generated: it is pretty surprising that you also got the javadoc error ...

+10
Jun 12 '09 at 13:20
source share

I came across the same error and using http://www.inonit.com/cygwin/jni/helloWorld/header.html 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 the name of my package, and C:\Prachi\Android\Workspace_QP_re structure\ is the path of my eclipse workspace.

Hope this helps you

+9
Jun 07 2018-11-11T00:
source share

I got this problem when I add my source to the -classpath directory. I thought the classes are in * .java files;)

Javah is working on byte code, so you need to add the directory with your binaries to the classpath

I did 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 a file and run

+4
Dec 21 '10 at 12:20
source share

In my case, the problem was pretty dumb. I will try: javah com.aaa.bbb.ClassName. the class

without ".class" I am creating the .h file correctly

javah com.aaa.bbb.ClassName

+3
Dec 29 '11 at 9:36
source share

I had similar problems and I used the -verbose option. I had to add; before the classpath parameter.

 C:\Projects\HelloWorld\src>javah -verbose -classpath c:\projects\HellowWorld\build\classes helloworld.HelloWorld error: cannot access helloworld.HelloWorld class file for helloworld.HelloWorld not found javadoc: error - Class helloworld.HelloWorld not found. [ Search Path: c:\jdk\jre\lib\resources.jar;c:\jdk\jre\lib\rt.jar;c:\jdk\jre\lib \sunrsasign.jar;c:\jdk\jre\lib\jsse.jar;c:\jdk\jre\lib\jce.jar;c:\jdk\jre\lib\ch arsets.jar;c:\jdk\jre\classes\c:\projects\HellowWorld\build\classes ] Error: No classes were specified on the command line. Try -help. C:\Projects\HelloWorld\src>javah -verbose -classpath ;c:\projects\HellowWorld\build\classes helloworld.HelloWorld [ Search Path: c:\jdk\jre\lib\resources.jar;c:\jdk\jre\lib\rt.jar;c:\jdk\jre\lib\sunrsasign.jar;c:\jdk\jre\lib\jsse.jar;c:\jdk\jre\lib\jce.jar;c:\jdk\jre\lib\charsets.jar;c:\jdk\jre\classes\;c:\projects\HellowWorld\build\classes ] [Creating file helloworld_HelloWorld.h] [search path for source files: .,c:\projects\HellowWorld\build\classes] [search path for class files: c:\jdk\jre\lib\resources.jar,c:\jdk\jre\lib\rt.jar,c:\jdk\jre\lib\sunrsasign.jar,c:\jdk\jre\lib\jsse.jar,c:\jdk\jre\lib\jce.jar,c:\jdk\jre\lib\charsets.jar,c:\jdk\jre\classes,c:\jdk\jre\lib\ext\dnsns.jar,c:\jdk\jre\lib\ext\localedata.jar,c:\jdk\jre\lib\ext\sunjce_provider.jar,c:\jdk\jre\lib\ext\sunmscapi.jar,c:\jdk\jre\lib\ext\sunpkcs11.jar,.,c:\projects\HellowWorld\build\classes] [loading .\helloworld\HelloWorld.class] [loading java\lang\Object.class(java\lang:Object.class)] [loading java\lang\Throwable.class(java\lang:Throwable.class)] [loading java\lang\Class.class(java\lang:Class.class)] [done in 409 ms] 

Without., This is the end of the search path: C: \ JDK \ JRE \ Classes \ C: \ Projects \ HellowWorld \ build \ classes

I was able to go this far from the examples above.

+2
Apr 02 2018-12-12T00:
source share

For Windows ...

FILE DETAILS

 javaFileName: HelloWorld.java packageCode: "package com.accessibility;" importCode: "import com.accessibility.HelloWorld;" javaFileLocation: "S:\Accessibility\tools\src\test\java\com\accessibility\HelloWorld.java" 

JavaFileLocation should be considered as having two parts ...

 classpath: "S:\Accessibility\tools\src\test\java" relativeFilePath: "com\accessibility\HelloWorld.java" 

CREATE CLASS FILE

The second line below was launched 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" 

CREATE STAND FILE

The second line below was launched 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" 
+2
Aug 09 '13 at 20:02
source share

problem with cygwin:

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 fine using the -classpath . option -classpath .

 $ javah -classpath . com.example.JavaHowTo $ ls *.h com_example_JavaHotTo.h 

More tricks:

  • The default option is -jni by default, so it is not required.
  • You can specify a relative / absolute classpath
  • But javah on MS-Windows prefers the path à la C:\Workspace\prj\bin
  • Use cygpath -w /cygdrive/c/Workspace/prj/bin to convert to MS-Windows format
  • Use the -d your/jni/headers/path option -d your/jni/headers/path to write headers to another directory
  • javah 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 
+1
Jan 21 '13 at 16:12
source share

He worked with me:
For the window:
If the path file is .class: D: \ workspace \ JNI Demo \ build \ classes \ jni \ demo and in the hava Netbeans package: jni.demo.HelloWorld.java
First, I buijd the .java file into a .class file.
.Class path file: D: \ workspace \ JNI Demo \ build \ classes \ jni \ demo \ HelloWorld.class
Secondly, I dir D: \ workspace \ JNI Demo \ build \ classes
And javah -jni jni.demo.HelloWorld
Finally, the result of the .j file is created in the path: D: \ workspace \ JNI Demo \ build \ classes

+1
Dec 14 '15 at 3:15
source share

I am using Eclipse.

Command syntax:

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

outputdir is the directory in which the header file is created.

classpath - Contains the absolute path to the directory containing the root package.

fully_qualified_class - The name of the class containing the WITHOUT .class extension built-in methods

The following file is created:

C: \ Users \ John \ workspace \ JNITest \ Bin \ com \ Canessa \ john \ jnitest \ com_canessa_john_jnitest_CallMyCLib.h

The contents of the generated header file:

 /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class com_canessa_john_jnitest_CallMyCLib */ #ifndef _Included_com_canessa_john_jnitest_CallMyCLib #define _Included_com_canessa_john_jnitest_CallMyCLib #ifdef __cplusplus extern "C" { #endif /* * Class: com_canessa_john_jnitest_CallMyCLib * Method: helloInC * Signature: ()V */ JNIEXPORT void JNICALL Java_com_canessa_john_jnitest_CallMyCLib_helloInC (JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif 
+1
Dec 19 '16 at 14:22
source share

Go to your bin folder of your Java project via the cmd command prompt.

 cd "Path to the bin directory of your java project" 

Then

 javah "Your Package"."Name Of Your Java Class" 
0
Feb 23 '14 at 9:00
source share

They worked after me ... Go to the project path from the terminal, for example,

/ home / usr / Desktop / Workspace / ProjectName / src / main / java

and click the following command,

javah -jni com.abc.test.callfileName (without .class extension)

com_abc_test_className.h file will be created in the following path / home / usr / Desktop / Workspace / ProjectName / src / main / java

finally the command looks, [my-machine / usr] $ / home / usr / Desktop / Workspace / ProjectName / src / main / java / src / main / java> javah -jni com.abc.test.className

0
Mar 03 '16 at 9:57
source share
 How to generate a `JNI Header` file from an` Android class` file using `javah` (` .java` or `.class` BOTH work equally well). 
For Eclipse project on Windows:
Goto the directory where the src, bin and jni folders are (so we can use relative paths to src or bin and jni): cd C: \ Android \ workspace5 \ AndroidImageFilter I assume `javah` is in your` PATH` (It is in something like: `C: \ Program Files \ Java \ jdk1.7.0_79 \ bin \ javah.exe`): javah -classpath c: \ Android \ sdk \ platforms \ android-19 \ android.jar; ./ src / -d ./jni cn.Ragnarok.NativeFilterFunc ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ | | | | | | | | | Your android: targetSdkVersion = "16" ---------------------------- + | | | | | | | | | | | | | | | | | | | | | | | path to android.jar --------- + ----------------------------------- ---- + | | | | | | | | | | | | | | | | | | | | | | | | semicolon (;) important! -------------------------------------------------- + | | | | | | | | | | You can use the source directory (yes you can!) (OR the / bin / classes / dir) ----- + | | | | | | | | Where to put the output file (cn_Ragnarok_NativeFilterFunc.h in this case) ----------- + --- + | | | | The dot (.) Spearated full package name path to the .java source file WITH file name -------- + | | File name of a java class -------------------------------------------- ----------------------------------------- + For Android Studio on Windows e'g ': ^ cd C: \ Android \ workspace5 \ AndroidImageFilter \ app \ src \ main | and usr java INSTEAD of src -------------------------------------------- -------- +

See http://kn-gloryo.imtqy.com/Build_NDK_AndroidStudio_detail/ for details.

If you have many file names (Java classes), you can use a file with a list of classes.
If you are on Linux or MAC-OS, use ":" (a colon) to separate directories for pathpath, not ";"
See Link http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javah.html

0
Feb 08 '17 at 12:32
source share



All Articles