JNI 和 Java:ant 调用 make 还是 make 调用 ant?

发布于 2024-07-04 07:08:33 字数 328 浏览 7 评论 0原文

我即将第一次进入 JNI(Java 本机接口)的世界,以提供从平台特定的 C/C++ 代码到 Java 的文件系统更改通知。 除非有人推荐一些我错过的出色的图书馆来做这件事。

作为 JNI 的新手,我已经设法找到了很多关于 JNI 接口方面和库生成方面的文档,但我还没有找到太多关于构建本机库的文档。

我有一个基于 ant 的现有构建,用于预先存在的 Java 源代码,因此我正在尝试确定是否应该让 ant 调用 make 来创建库,或者最好在创建后让 make 调用 ant图书馆?

这两个选项都显得非常好,但两者似乎都比尝试让 ant 调用编译器来编译代码并直接生成库更好。

I'm just about to make my first trip into the world of JNI (Java Native Interface) to provide file system change notifications from platform specific C/C++ code to Java. That is unless someone suggest some brilliant library for doing this that I've missed.

Being new to JNI I've managed to find much documentation on the interface side of it and library generation side of it, but I've not found much on building the native library.

I've got an existing build based on ant for the pre-existing Java source, so I'm trying to work out if I should get ant to call make to create the library or if it's best to get make to call ant after creating the library?

Neither option jumps out as being terribly nice, but both seem better than trying to get ant to call a compiler to compile the code and generate the library directly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

韶华倾负 2024-07-11 07:08:33

我非常不喜欢 make,因为它隐含的规则集和对空白的处理。 就我个人而言,我会使用 cpp 任务 (http://ant-contrib.sourceforge.net/cpptasks /index.html)来进行我的 C 编译。 它们不像 make 那样灵活,但也远没有那么复杂,这意味着您不必为开发人员增加学习 make 的负担。

I strongly dislike make because of its implicit ruleset and treatment of whitespace. Personally I would use cpp tasks (http://ant-contrib.sourceforge.net/cpptasks/index.html) to do my C compilation. They are not as flexible as make but they are also far less complex and it will mean you don't have to burden your developers with learning make.

谎言月老 2024-07-11 07:08:33

您还可以在 Codemesh 尝试 terp C++ 任务。 它们不是免费的,但它们提供了高水平的抽象,以及发现/指定 C++ 编译器的能力以及为多平台构建迭代多个编译器/处理器架构/编译器配置的能力。

You could also try the terp C++ tasks at Codemesh. They are not free but they offer a high level of abstraction coupled with the ability to discover/specify the C++ compiler and the ability to iterate over more than one compiler/processor architecture/compiler configuration for multiplatform builds.

凉风有信 2024-07-11 07:08:33

我会完全跳过 JNI,并使用在标准输出上写入通知的外部程序。 然后,Java 可以简单地从程序输出流中读取并生成任何必要的事件。 如果您只想发送简单的通知,JNI 的工作量就太大了。

另外,在 Linux 上,您可以简单地启动“inotifywait”(使用一些合适的参数,请参阅“man inotifywait”)。

I'd skip JNI entirely, and use an external program which writes notifications on standard-output. Java can then simply read from the programs output stream and generate whatever event is necessary. JNI is way too much work if all you want is to send simple notifications.

Also, on Linux you can simply start "inotifywait" (with some suitable parameters, see "man inotifywait").

过去的过去 2024-07-11 07:08:33

作为 JNI 的更简单替代方案,请尝试 JNA:https://jna.dev.java.net/,可能会为你解决这个麻烦并且更简单(假设它可以做你想做的事情)。

As a simpler alternative to JNI, try JNA: https://jna.dev.java.net/, may solve this hassle for you and be simpler (assuming it can do what you want).

两个我 2024-07-11 07:08:33

我现在正在做类似的事情。 请注意,使用 swig.org 中的 swig 通常更容易,因为它会为您生成本机库的存根。

对您问题的简短回答是,ant 文件应该在构建 java 库之后运行 make 文件,因为本机库依赖于 swig 生成的标头,该标头是从 java 类文件生成的。

如果您非常熟悉 ant,并且不想学习新系统,那么 http://ant-contrib.sourceforge.net/cpptasks/index.html,也由另一张海报链接,将让您在 ant 中构建 C++。

I'm working on something similar right now. Be aware that using swig from swig.org is often easier as it generates the stubs to the native library for you.

The short answer to your question is that the ant file should run the make file after the java library has already been built, as the native library depends on the swig generated header, which is generated from the java class files.

If you are super familiar with ant, and don't want to learn a new system, then http://ant-contrib.sourceforge.net/cpptasks/index.html, also linked by another poster, will let you build c++ in ant.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文