Java System.loadLibrary 依赖项

发布于 2024-10-08 01:49:40 字数 511 浏览 0 评论 0原文

我使用的第 3 方 jar 正在尝试使用 System.loadLibrary 加载本机库。我认为正在发生的事情是正在加载的库之一依赖于另一个本机库。在这种情况下,指向 -Djava.library.path 无法正常工作。应用程序站点的说明是将 dll 放入 jre/bin 目录中,但我认为这是一个非常糟糕的主意(尤其是在尝试部署到客户端站点时)。

所以,这个问题实际上是由两部分组成。

  1. 如果本机库尝试加载另一个 -Djava.library.path 不起作用的本机库,这是否有意义?

  2. 有没有好的解决方案来解决这个问题?我想我可以在所有 dll 上显式调用 System.loadLibrary (我什至不确定这是否有效),但我需要确保以正确的顺序调用它们,否则我会遇到同样的问题。

编辑:我认为这是有道理的,它正在发生,到目前为止我读过的最好的解决方案是使用依赖步行器来找出它,然后以相反的顺序加载它们......但我愿意接受更好的建议。 ..

谢谢, 杰夫

A 3rd party jar I use is trying to load a native library using System.loadLibrary. I think what is happening is that one of the libraries being loaded has a dependency on another native library. Pointing -Djava.library.path does not work properly in this case. The instructions from the app's site is put the dlls in the jre/bin directory, but I think this is a really bad idea (especially when trying to deploy to client sites).

So, this question really is 2 parts.

  1. Does it make sense that if a native lib tries to load another native lib that -Djava.library.path does not work?

  2. Is there a good solution for working around this problem? I guess I could explicitly call System.loadLibrary on all of the dlls (I'm not even sure if this would work), but I would need to make sure to call them in the correct order otherwise I'll have the same problem.

EDIT: I think this makes sense that it is happening, and the best solution I've read so far is to use dependency walker to figure it out and then load them in reverse order...but I'm open to better suggestions...

thanks,
Jeff

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

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

发布评论

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

评论(1

梦屿孤独相伴 2024-10-15 01:49:40

是的,本机库不使用 Java 属性 -Djava.library.path 链接到其他本机库是有道理的。

一些可能的方法:

  • 第三方jar被固定加载自己的依赖项,依赖于java.library.path。
  • 您的代码以反向拓扑排序加载第三方 jar 所需的 DLL。但是,这会使您的代码指定第三方 jar 的依赖项。这些依赖关系可能会改变。
  • 您使用特定于操作系统的 DLL 搜索路径(例如,在 Unix/Linux/Mac 上使用 LD_LIBRARY_PATH,或在 Windows 上使用 PATH)。但是,这可能需要启动脚本。

Yes, it makes sense that native libraries do not use the Java property -Djava.library.path to link to other native libraries.

Some possible approaches:

  • The third-party jar is fixed to load its own dependencies, relying on java.library.path.
  • Your code loads the DLLs required by the third-party jar in a reverse topographic sort. However, this makes your code specify the dependencies of the third-party jar. Those dependencies might change.
  • You use the OS-specific DLL search path (e.g., using LD_LIBRARY_PATH on Unix/Linux/Mac, or PATH on Windows). However, this might require a startup script.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文