如何在 JAR 中捆绑原生库和 JNI 库? [英] How to bundle a native library and a JNI library inside a JAR?

查看:43
本文介绍了如何在 JAR 中捆绑原生库和 JNI 库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有问题的图书馆是东京内阁.

我希望将本机库、JNI 库和所有 Java API 类放在一个 JAR 文件中,以避免重新分发的麻烦.

I want is to have the native library, JNI library, and all Java API classes in one JAR file to avoid redistribution headaches.

似乎有在 GitHub 上尝试这样做,但是

  1. 不包含实际的原生库,仅包含 JNI 库.
  2. 它似乎是特定于 Leiningen 的原生依赖插件(它不能作为可再分发).
  1. It does not include the actual native library, only JNI library.
  2. It seems to be specific to Leiningen's native dependencies plugin (it won't work as a redistributable).

问题是,我可以将所有内容捆绑在一个 JAR 中并重新分发吗?如果是,怎么做?

The question is, can I bundle everything in one JAR and redistribute it? If yes, how?

P.S.:是的,我知道它可能会影响可移植性.

P.S.: Yes, I realize it may have portability implications.

推荐答案

可以创建一个包含所有依赖项的单个 JAR 文件,包括一个或多个平台的本机 JNI 库.基本机制是使用 System.load(File) 来加载库,而不是使用典型的 System.loadLibrary(String) 来搜索 java.library.path 系统属性.这种方法使安装更加简单,因为用户不必在他的系统上安装 JNI 库,但代价是可能不支持所有平台,因为平台的特定库可能不包含在单个 JAR 文件中.

It is possible to create a single JAR file with all dependencies including the native JNI libraries for one or more platforms. The basic mechanism is to use System.load(File) to load the library instead of the typical System.loadLibrary(String) which searches the java.library.path system property. This method makes installation much simpler as the user does not have to install the JNI library on his system, at the expense, however, that all platforms might not be supported as the specific library for a platform might not be included in the single JAR file.

流程如下:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆