eclipse 如何在Eclipse中生成JNI头文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9940381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:56:10  来源:igfitidea点击:

How to generate JNI header file in Eclipse

javaceclipseheaderjava-native-interface

提问by holy

I am using Eclipse to generate a JNI header file. I looked in program files\java\jre6\binand found a lot of .exeand .dllfiles, but I couldn't find the command javahwhich was in the documentation for using JNI to create bindings to C libraries.
Any help?

我正在使用 Eclipse 生成 JNI 头文件。我查看program files\java\jre6\bin并发现了很多.exe.dll文件,但我找不到javah使用 JNI 创建 C 库绑定的文档中的命令。
有什么帮助吗?

回答by Java42

Use the following panel to define a new external tool for javah.exe.

使用以下面板为 javah.exe 定义新的外部工具。

Point "Location" to the javah.exe tool.

将“位置”指向 javah.exe 工具。

Set "Working Directory" to

将“工作目录”设置为

${workspace_loc:/${project_name}/bin}

Set "Arguments" to:

将“参数”设置为:

-classpath ${project_classpath} -v -d ${workspace_loc:/${project_name}/src} ${java_type_name}

enter image description here

在此处输入图片说明

To run the tool, highlight the java source file in package explorer and run the tool.

要运行该工具,请在包资源管理器中突出显示 java 源文件并运行该工具。

enter image description here

在此处输入图片说明

Press F5 to refresh th project to see the newly generated file.

按 F5 刷新项目以查看新生成的文件。

回答by Kai Mechel

Just some info...

只是一些信息...

Unfortunately the solution above did not work out for me, but the solution in this thread did:

不幸的是,上面的解决方案对我不起作用,但这个线程中的解决方案做到了:

Using javah -jni with an Eclipse project structure

将 javah -jni 与 Eclipse 项目结构一起使用

With the above mentioned arguments, I got:

有了上面提到的论点,我得到了:

Exception in thread "main" java.lang.IllegalArgumentException: Not a valid class name:path/to/project

Exception in thread "main" java.lang.IllegalArgumentException: Not a valid class name:path/to/project

I found out, that the problem was a space character in the path to my project. Wrapping the paths in quotes did help for the solution above.

我发现问题出在我的项目路径中的空格字符。将路径用引号括起来确实有助于上述解决方案。

回答by halo89

Location

地点

// javah.exe path

// javah.exe 路径

C:\Program Files\Java\jdk1.7.0_79\bin\javah.exe

C:\Program Files\Java\jdk1.7.0_79\bin\javah.exe

Working Directory

工作目录

${workspace_loc:/${project_name}/bin}

${workspace_loc:/${project_name}/bin}

Arguments

参数

-classpath ${project_classpath} -v -d ${workspace_loc:/${project_name}/jni} ${java_type_name}

-classpath ${project_classpath} -v -d ${workspace_loc:/${project_name}/jni} ${java_type_name}

open java class and run tools

打开java类并运行工具