如何使目标库可供我的 Java 应用程序使用?

发布于 2024-08-23 09:50:45 字数 284 浏览 3 评论 0原文

使用 JNA,文档说:

使您的目标库可供 Java 程序使用。有两种方法可以执行此操作: 首选方法是将 jna.library.path 系统属性设置为目标库的路径。此属性类似于 java.library.path,但仅适用于 JNA 加载的库。

这实际上意味着什么?如何设置jna.library.path系统属性?我的应用程序需要引用 Kernel32.dll

谢谢

Using JNA, the documentation says:

Make your target library available to your Java program. There are two ways to do this: The preferred method is to set the jna.library.path system property to the path to your target library. This property is similar to java.library.path but only applies to libraries loaded by JNA.

What does this actually mean? How do I set the jna.library.path system property? My app needs to reference Kernel32.dll

Thanks

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

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

发布评论

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

评论(1

如梦亦如幻 2024-08-30 09:50:45

在命令行调用Java虚拟机时,可以使用参数“-D”设置系统属性:

java -Djna.library.path=<您的库的路径>主类

当从配置文件中读取它时,您还可以在应用程序启动时在代码中以编程方式设置它:

System.setProperty("jna.library.path", <库的路径>);

我自己没有使用过JNA,所以我不知道当你在代码中设置值时,对于JVM来说是否真的太晚了。在这种情况下,请选择第一个选项。

You can set system properties by using the parameter "-D" when you invoke the Java Virtual Machine on the command line:

java -Djna.library.path=<path to your library> MainClass

You can also set this programmatically in your code at your applications's startup when it has been read from e.g. a config file:

System.setProperty("jna.library.path", <path to your library>);

I haven't used JNA myself, so I don't know if it is actually too late for the JVM when you set the value in code. In that case, go with the first option.

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