gpt4 book ai didi

java - 找不到合适的 native 库。 native.libpath.* 与 java.library.path

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:57:12 26 4
gpt4 key购买 nike

我在运行某些库 (HDF5) 时遇到“找不到合适的 native 库”。

完整轨迹如下:

java.lang.ExceptionInInitializerError
at ch.systemsx.cisd.hdf5.hdf5lib.HDF5Constants.javaToC(HDF5Constants.java:1938)
at ch.systemsx.cisd.hdf5.hdf5lib.HDF5Constants.<clinit>(HDF5Constants.java:982)
at ch.systemsx.cisd.hdf5.CharacterEncoding.<clinit>(CharacterEncoding.java:29)
at ch.systemsx.cisd.hdf5.HDF5BaseReader.<init>(HDF5BaseReader.java:137)
at ch.systemsx.cisd.hdf5.HDF5BaseWriter.<init>(HDF5BaseWriter.java:147)
at ch.systemsx.cisd.hdf5.HDF5WriterConfigurator.writer(HDF5WriterConfigurator.java:133)
at ch.systemsx.cisd.hdf5.HDF5FactoryProvider$HDF5Factory.open(HDF5FactoryProvider.java:48)
at ch.systemsx.cisd.hdf5.HDF5Factory.open(HDF5Factory.java:47)
at tests.jhdf5.TestHDF5.testReaderWriter(TestHDF5.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
...
Caused by: java.lang.UnsupportedOperationException: No suitable HDF5 native library found for this platform.
at ch.systemsx.cisd.hdf5.hdf5lib.H5.<clinit>(H5.java:41)
... 30 more

如您所见,库是从 HDF5 java 库中调用的。

Java 库作为全局库中的一堆 jar 附加:

enter image description here

如您所见,包含 native 库。

问题是这个设置是否足够?我可能需要将一些目录添加到 PATH 变量中吗?

更新

我发现,HDF5 代码需要 native.libpath.jhdf5 中的库,代码来自 ch.systemsx.cisd.base.utilities.NativeLibraryUtilities#loadNativeLibrary():

public static boolean loadNativeLibrary(String libraryName) {
String linkLibNameOrNull = System.getProperty("native.libpath." + libraryName);
if(linkLibNameOrNull != null) {
return loadLib(linkLibNameOrNull);
} else {
String linkLibPathOrNull = System.getProperty("native.libpath");
if(linkLibPathOrNull != null) {
linkLibNameOrNull = getLibPath(linkLibPathOrNull, libraryName);
return loadLib(linkLibNameOrNull);
} else {
linkLibNameOrNull = tryCopyNativeLibraryToTempFile(libraryName);
return linkLibNameOrNull != null?loadLib(linkLibNameOrNull):loadSystemLibrary(libraryName);
}
}
}

当 IntelliJ 设置 java.library.path 时:

   public static void main(String[] args) {

System.out.println("native.libpath.jhdf5 = " + System.getProperty("native.libpath.jhdf5") );
System.out.println("java.library.path = " + System.getProperty("java.library.path") );

打印:

native.libpath.jhdf5 = null
java.library.path = D:\Users\Dims\Design\!Lib\sis-jhdf5-SNAPSHOT-r32355\sis-jhdf5\lib\nativejar\hdf5-windows-intel.jar

为什么?

最佳答案

你可能和我有同样的问题。问题是我已经包含了 3 个不同平台(linux、windows 和 macOS)的 jar,因此发生了冲突,这个问题发生了

如果它没有解决问题(就像我的问题一样),我建议咨询 jhdf5 常见问题解答 https://wiki-bsse.ethz.ch/display/JHDF5/JHDF5+FAQ

关于java - 找不到合适的 native 库。 native.libpath.* 与 java.library.path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33244717/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com