问题描述
可以在执行Java应用程序之前或期间设置java.library.path(通过设置Java库路径的全局环境变量或在运行Java exec jar时使用标志).是否可以像使用Class-Path的类一样在Java jar的清单文件中设置它?听起来像应该支持的功能(如果不存在).
The java.library.path can be set before or during the execution of a java app (either by setting the global environment variables of the java library path or by using a flag when running the java exec jar). Can it be set inside the manifest file of the java jar, as is done for classes with Class-Path? Sounds like a feature that should be supported, if it does not exist.
由于如 stdunbar 所述,清单文件不支持java.library.path映射,因此我为使用清单文件添加了另一种解决方案.
EDIT : since as stdunbar mentioned, the manifest file does not support java.library.path mappings, I've added an answer with an alternative solution to using the manifest file.
推荐答案
由于无法使用清单文件设置java.library.path,因此我四处寻找替代解决方案.一个不错的方法是通过实际的应用程序代码设置java.library.path:以编程方式设置java.library.path
Since java.library.path can not be set using the manifest file, I looked around for an alternative solution.A nice one is setting java.library.path via the actual application code:setting java.library.path programmatically
这解决了我的部署问题,例如超级按钮(不需要额外的脚本来手动设置-Djava.library.path).
This solved my deployment issues like a charm (no need for an additional script to manually set the -Djava.library.path).
请注意,如果需要更动态的解决方案,则可以将添加的库路径存储在配置文件中,该文件在设置java.library.path时会读取.
Note that if a more dynamic solution is required, the added library path can be stored in a configuration file which is read when setting the java.library.path.
更新了链接,感谢@uchuugaka
Updated link, thanks to @uchuugaka
这篇关于将java.library.path添加到Java清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!