Using javah on linux

ぐ巨炮叔叔 提交于 2019-12-20 02:04:06

问题


I have a simple class for use on JNI, which i need to export to a header file (.h).

I've read that I need to use the javah command, by going to the src folder of the project, and type:

javah -jni com.main_package.NativeClass 

On windows it works fine, but on my main OS (Linux) it doesn't. It keeps telling that it can't find the class. I've tried to use many combinations of the command and to run it on many possible paths, but it didn't work. I've followed many tutorials and websites (including here) and tried their combinations too.

I even tried using Eclipse's external tool for this, as shown here, but it has also shown the same error.

The error I get looks like this:

error: cannot access com.main_package.NativeClass 
class file for com.main_package.NativeClass  not found
javadoc: error - Class com.main_package.NativeClass  not found.
Error: No classes were specified on the command line.  Try -help.

Can anyone please help me? I really like working on Linux and wouldn't want to switch OS each time i need to use this tool.


Here's the correct answer:

  1. for console , go to the "bin/classes" folder and run the command i've used :

    javah -jni com.main_package.NativeClass

  2. for eclipse , use the link i gave , but instead of ${project_loc}/bin/ use ${project_loc}/bin/classes/ , and then , in the package explorer , go to the NativeClass.java , and run the external tool . the output will be in the same path as of the java file .


回答1:


You don't go to src folder of the project, but the root of your compiled .class files (where com subfolder exists or is created). javah is looking for compiled class, not your source file. If you just run javac manually, the class file will be in the same location as the original sources. Then the statement "go to src folder" is correct. However if you have a project in Eclipse or you use ant or something, the classes might be in completely different location - depending on how your project is set up. I would guess that the Eclipse projects on your Windows and on your Linux are set up differently.




回答2:


You don't have to use javah on the class files. You can use javah directly on the source files (.java) to generate the native C/++ signature (header) file. Ex:

javah -cp /Users/Android/android-sdk/platforms/android-xy/android.jar;. com.test.JniTest


来源:https://stackoverflow.com/questions/11135720/using-javah-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!