fail to load a native library using activator (Play Framework)

后端 未结 1 373
执念已碎
执念已碎 2021-01-07 13:02

I\'m trying to load a native library in my Play 2.4.x application. I have written a simple test that works fine both in the IDE (IntelliJ) and in SBT. In both case I\'m sett

1条回答
  •  广开言路
    2021-01-07 13:49

    I found a solution to the issue here.

    The native library and its java counterpart must be in the same class loader.

    Create a class similar to:

    public final class PlayNativeLibraryLoader {
        public static void load(String libraryPath) {
            System.load(libraryPath);
        }
    }
    

    And now you can use it in the Play startup lifecycle.

    object Global extends GlobalSettings {
    
      override def beforeStart(app: Application) = {
        PlayNativeLibraryLoader.load(app.getFile("./lib/lindoapi/linux64/liblindojni.so").getPath)
        Logger.info("Lindo native library loaded")
      }
    
    }
    

    0 讨论(0)
提交回复
热议问题