J++到Java:如何从RNI迁移到JNI?

发布于 2024-08-04 20:09:17 字数 446 浏览 3 评论 0原文

我继承了一个遗留的 J++ 项目。我已经成功地将这个项目升级到标准 Sun Java。

但是,该项目包含一个本机 C++ dll,Java 代码通过 Microsoft 特定的 与其进行通信RNI框架

不用说,调用 System.loadLibrary("myRniNativeDll") 现在会抛出 UnsatisifiedLinkError,表示无法找到依赖项之一。

我完全不知道如何将 C++ RNI dll 迁移到 JNI dll;我不知道从哪里开始。我有 C++ 源代码,但我不知道如何构建 JNI dll。 Java 专家可以向我提供任何提示/教程/在线材料吗?

I've inherited a legacy J++ project. I've upgraded this project to standard Sun Java successfully.

However, this project includes a native C++ dll which the Java code talks to via the Microsoft-specific RNI framework.

Needless to say, calling System.loadLibrary("myRniNativeDll") now throws a UnsatisifiedLinkError, saying one of the dependencies couldn't be found.

I'm totally clueless how to migrate a C++ RNI dll to a JNI dll; I've no idea where to begin. I have the C++ source code, but I don't know how to build a JNI dll. Are there any tips/tutorials/online materials you Java experts can point me to?

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

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

发布评论

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

评论(5

給妳壹絲溫柔 2024-08-11 20:09:17

如果许可是可接受的 (LGPL),Java Native Access 提供比 JNI 更友好的 FFI ;移植可能会减少到剥离 RNI 层并仅公开一个简单的“C”可调用 API。

If the licensing is acceptable (LGPL), Java Native Access provides a rather friendlier FFI than the JNI does; porting may reduce to stripping away the RNI layer and just exposing a simple 'C'-callable API.

属性 2024-08-11 20:09:17

看一下 JNA - 可能可以通过这种方式直接访问 RNI DLL;或者至少它会使移植工作比手动执行 JNI 容易得多。

Take a look at JNA - it might be possible to access the RNI DLL directly that way; or at least it will make the job of porting it much easier than doing JNI manually.

独闯女儿国 2024-08-11 20:09:17

如果可能的话,我建议你考虑避免RNI ->通过用纯Java重写C++代码来解决JNI移植问题。

编写 JNI 代码需要非常小心,如果出错,就会使 JVM 稳定性面临风险。我的建议是尽可能避免它。

If possible, I suggest that you consider avoiding the RNI -> JNI porting problem by rewriting the C++ code in pure Java.

Writing JNI code requires a huge amount of care, and places JVM stability at risk if you get it wrong. My advice is to avoid it if you possibly can.

手长情犹 2024-08-11 20:09:17

虽然我从未使用过 Microsoft 的 RNI,只使用过 Sun 的 JNI,但我希望您不能直接使用 RNI 样式的 DLL,就好像它是 JNI 样式的 DLL 一样。我也不知道有什么可以自动将 RNI 转换或桥接到 JNI。

您没有提到您是否拥有 C++ RNI DLL 的源代码,尽管我假设您有,因为您提到了继承该项目。如果您有任何 C++/C 经验,并且非常了解 RNI DLL 提供的功能,那么将其移动到 JNI 应该不会太困难。移植它所投入的时间可能会为维持它的前进带来回报。

您在 Wikipedia 上提供的 JNI 条目链接有很多有关使用 JNI 进行编码的有用链接。如果没有更多细节,很难给出任何其他建议。

While I have never used Microsoft's RNI, only Sun's JNI, I would expect that you couldn't directly use an RNI-style DLL as if it were a JNI-style DLL. I am also unaware of anything that would automatically convert or bridge RNI to JNI.

You do not mention if you have the source to the C++ RNI DLL, although I'll assume you do since you mention inheriting the project. If you have any C++/C experience, and have a good idea of what functionality the RNI DLL is providing, it should not be too difficult to move it to JNI. The time invested in porting it would likely pay off for maintaining it moving forward.

The link you provided to the JNI entry on Wikipedia has lots of helpful links on coding with JNI. Without a bit more detail, it is hard to give any other advice.

梦过后 2024-08-11 20:09:17

Java 本机接口:程序员指南和规范 是我找到的最好的资源用于编写 JNI 代码。它不包括 RNI -> JNI,但它是学习 JNI 如何工作的一个很好的*起点。

*它实际上很枯燥,读起来也不是特别有趣,但它是我能找到的最好的。

Java Native Interface: Programmer's Guide and Specification is the best resource that I've found for writing JNI code. It doesn't cover RNI -> JNI, but it is a great* starting point for learning how JNI works.

*It's actually very dry, and not particularly fun to read, but it's the best I've been able to find.

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