简体   繁体   English

如何为我的Java应用程序提供目标库?

[英]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 to java.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.

相关问题 如何使服务器上的文件可用于客户端Web浏览器(使用Java编写的服务器) - How do I make files on my server available to client webbrowser, server written in Java 如何从Java应用程序拨打语音电话? 如何使该程序正常工作? - How do I make a voice call from my Java app? How do I make this program work? 如何使用Java库? - How do I make use of java library? 如何使用 Eclipse 创建 Java 库? - How do I make a Java library with Eclipse? 如何使Java ClassLoader知道可用的类? - How do I make the java ClassLoader aware of available classes? 如何使Java CLI解析库Jopt Simple解析参数而没有任何选择? - How do I make my Java CLI parsing library Jopt Simple parse an argument without any option? 如何使Java 7 OSX App仅可在工具栏上拖动 - How do I make my Java 7 OSX App draggable on toolbar only 如果我使用的库的源和目标级别为1.7,如何将我的项目编译为java 1.5? - How to compile my project to java 1.5 if the library I use has source and target level of 1.7? 如何让我的应用程序出现在app chooser中? - How do I make my app appear in app chooser? 如何在Java应用程序中使用Python库? - How do I use a Python library in my Java application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM