[英]How do I make a target library available to my Java app?
Using JNA, the documentation says: 使用JNA,文档说:
Make your target library available to your Java program.
使目标库可用于Java程序。 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.有两种方法可以执行此操作:首选方法是将
jna.library.path
系统属性设置为目标库的路径。 This property is similar tojava.library.path
but only applies to libraries loaded by JNA.此属性类似于
java.library.path
但仅适用于JNA加载的库。
What does this actually mean? 这究竟意味着什么? How do I set the
jna.library.path
system property? 如何设置
jna.library.path
系统属性? My app needs to reference Kernel32.dll
我的应用程序需要引用
Kernel32.dll
Thanks 谢谢
You can set system properties by using the parameter "-D" when you invoke the Java Virtual Machine on the command line: 在命令行上调用Java虚拟机时,可以使用参数“-D”设置系统属性:
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 eg 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. 我自己没有使用JNA,所以当你在代码中设置值时,我不知道JVM实际上是否为时已晚。 In that case, go with the first option.
在这种情况下,请使用第一个选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.