将JNI库添加到本地Maven存储库 [英] Adding a JNI library to the local Maven Repository
问题描述
我希望使用Maven将JNI库(包括其共享对象(.so)文件)添加到我的项目中。不幸的是它还没有在公共存储库中,所以我想我必须自己在我的本地存储库中安装它才能使它工作。
I wish to add a JNI library, including its shared object (.so) file to my project using Maven. Unfortunately it is not yet on a public repository so I guess I have to install it myself on my local repository to have it working.
我如何去包括本机部分在Maven中捆绑在我的项目中(最终使用copy-dependencies插件导出)。这是一个标准的J2SE应用程序(不是网络应用程序),打包.jar?
How do I go about including the native part in Maven to be bundled in my project (and eventually exported with the copy-dependencies plugin). This is a standard J2SE app (not a web-app), with packaging .jar?
我想要添加的库是 junixsocket ,以防万一有助于了解。
它有一个.so(本机库)组件和Java .jar组件。
The library I am trying to add is junixsocket, just in case it helps to know. It has a .so (native library) component, and the Java .jar component.
我遇到了 maven-nar-plugin 似乎以本机构建为目标,但似乎更倾向于从代码构建JNI项目而不是捆绑第三方JNI库,我无法将拼图拼凑在一起。
I came across maven-nar-plugin which seems to target native builds, but seems to be more oriented towards building a JNI project from code, rather than bundling a 3rd party JNI library, and I can't get to piece the jigsaw puzzle together.
我该怎么做:
- 在我的本地存储库中安装这些文件,其中.jar取决于.so库。
- 包含依赖项(在POM文件中的.jar和.so)。
谢谢。
推荐答案
我的方法:
将 .so
文件放入存储库特定于平台的分类器,如下所示: sqlite3-3.7.9-linux-x86_64.so
。
为所有必需平台添加 .so
依赖项:
Put .so
files to repository with platform specific classifier, like this: sqlite3-3.7.9-linux-x86_64.so
.
Add .so
dependencies for all required platforms:
<dependency>
<groupId>de.ch-werner</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.9</version>
<type>so</type>
<classifier>linux-x86_64</classifier>
</dependency>
使用此maven程序集插件配置将所有本机库放入 lib / native
你的目录:
Use this maven assembly plugin config to put all native libs into lib/native
directory of you dist:
<dependencySet>
<outputDirectory>lib/native</outputDirectory>
<outputFileNameMapping>${artifact.artifactId}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
<unpack>false</unpack>
<useProjectArtifact>false</useProjectArtifact>
<useStrictFiltering>false</useStrictFiltering>
<includes>
<include>*:*:dll:*</include>
<include>*:*:so:*</include>
<include>*:*:jnilib:*</include>
</includes>
</dependencySet>
使用此类在app启动时加载库(计划将分类器命名更改为 GNU三胞胎):
Use this class to load libs on app startup (planning to change classifier naming to GNU triplets):
CtzJniUtils.loadJniLibsFromStandardPath(Launcher.class, "sqlite3")
这篇关于将JNI库添加到本地Maven存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!