找不到合适的本地库。 native.libpath。* vs java.library.path

时间:2015-10-20 18:58:42

标签: java path java-native-interface hdf5

运行某些库(HDF5)时遇到“找不到合适的本机库”。

完整跟踪如下:

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

如您所见,包括原生图书馆。

问题是此设置是否足够?我可能需要在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

为什么?

1 个答案:

答案 0 :(得分:1)

您可能遇到与我相同的问题。 问题是我已经为3个不同的平台(linux,windows和macOS)包含了jar,因此发生了冲突并且发生了这个问题

如果它没有解决案件(正如我的做法)我建议咨询jhdf5常见问题https://wiki-bsse.ethz.ch/display/JHDF5/JHDF5+FAQ