简体   繁体   中英

No suitable native library found. native.libpath.* vs java.library.path

I encounter "No suitable native library found" when running some library (HDF5).

Full trace is follows:

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

As you see, library is called from inside HDF5 java library.

Java library is attached as bunch of jars in global libraries:

在此输入图像描述

As you see, native library is included.

The question is whether this setting is sufficient? May be I require to add some directories to the PATH variable?

UPDATE

I found, that HDF5 code expects library inside native.libpath.jhdf5 , the code is from 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);
         }
      }
   }

While IntelliJ sets 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") );

prints:

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

Why?

You may have the same problem as me. The problem was that i had include the jar for the 3 differents platforms (linux, windows and macOS) thus there was a conflict and this problem happen

If it does not solved the case (as it has do in mine) i suggest to consult the jhdf5 faq https://wiki-bsse.ethz.ch/display/JHDF5/JHDF5+FAQ

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM