在Linux上使用javah的 [英] Using javah on linux

查看:156
本文介绍了在Linux上使用javah的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单类的JNI,我需要导出到一个头文件(.H)。

使用

我读过,我需要使用 javah的命令,通过去的的的src 文件夹项目,然后键入:

  javah的-jni com.main_package.NativeClass
 

在窗口它工作正常,但是在我的主操作系统(Linux)的事实并非如此。它不断地说,它无法找到类。我试着用命令的多种组合,并在许多可能的路径运行,但没有奏效。我跟着很多教程和网站(包括在这里),并试图它们的组合了。

我甚至尝试使用Eclipse的这个外部工具,因为这里显示 ,但它也显示出同样的错误。

我得到的错误是这样的:

 错误:无法访问com.main_package.NativeClass
找不到类文件com.main_package.NativeClass
的javadoc:错误 - 类com.main_package.NativeClass没有找到。
错误:没有类在命令行上指定。尝试 - 帮助。
 

谁能帮帮我吗?我真的很喜欢在Linux上工作,也不会想每次我需要使用这个工具时切换操作系统。


下面是正确答案:

  1. 控制台,转到斌/类文件夹,然后运行我用命令:

    javah的-jni com.main_package.NativeClass

  2. 有关日食,用我给的链接,但不是 $ {project_loc} /斌/ 使用 $ {project_loc} /斌/班/ ,然后在包资源管理器,进入NativeClass.java,并运行外部工具。输出将在相同的路径java文件的。

解决方案

您不去的src 文件夹中的项目,但你的根编<强>的.class 文件(其中 COM 子文件夹存在,或创建)。 javah的正在寻找编译后的class,而不是你的源文件。如果你只需要运行的javac 手动,类文件将在相同的位置与原始来源。那么语句去src文件夹是正确的。但是,如果你有在Eclipse项目或使用蚂蚁什么的,这些类可能是完全不同的位置 - 这取决于如何您的项目设置。我猜想,您的Windows,并在你的Linux的Eclipse项目都设置了不同的。

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 .

解决方案

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.

这篇关于在Linux上使用javah的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆