How can I include platform-specific native libraries in the .JAR file using Eclipse?

后端 未结 2 519
無奈伤痛
無奈伤痛 2021-01-05 14:16

I am just starting to learn JNI. I have been following a simple example, and I have created a Java app that calls a Hello World method in a native library. I\'d like to targ

相关标签:
2条回答
  • 2021-01-05 14:28

    For runnable JARs, what you need to do is extract to the temporary directory (maybe in a static { } block) and then load the DLL from that directory (using System.loadLibrary() in the same block). To do this, you need to subclass ClassLoader and override the findLibrary() method to allow libraries to be found in that directory. You can do whatever logic you need to here to load the particular platform libraries. To be honest, the naming for the libraries on the different platforms should be similar anyway -- I believe that you omit the 'lib' part when loading, and the extension. That's the gist of it. Probably easier to use One-JAR as the other poster mentioned :)

    0 讨论(0)
  • 2021-01-05 14:36

    You might want to check out the One-JAR project. It lets you package your application and its dependencies (including native libraries) to a single jar file.

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