仅使用必需平台的二进制文件来构建jar(javacpp) [英] Build jar with binaries for required platform only (javacpp)
问题描述
我想为 tesseract 制作一个胖子.通过以下构建设置,我得到了一个约68 MB的jar,带有所有受支持平台的依赖项:
I want to build a fat jar for tesseract. With the following build settings I get a jar of about 68 MB with dependencies for all supported platforms:
dependencies {
implementation group: 'org.bytedeco', name: 'tesseract-platform', version: '4.1.1-1.5.3'
}
jar {
manifest { attributes 'Main-Class': 'BasicExample' }
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
}
为了减小此大小,我尝试仅在本指南-但没有成功,另请参见此 POM文件:
In order to reduce this size, I tried to only include the dependencies for my platform following this guideline - but without success, see also this SO question and @Samuel Audet's answer to it (I want to stick with gradle). Therefore I decided to manually include only the required dependencies from the POM file:
dependencies {
implementation group: 'org.bytedeco', name: 'tesseract', version: '4.1.1-1.5.3'
implementation group: 'org.bytedeco', name: 'tesseract', version: '4.1.1-1.5.3', classifier: 'windows-x86_64'
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.79.0-1.5.3', classifier: 'windows-x86_64'
}
这会将jar的大小减小到大约7 MB,并且可以正常工作(至少对于
This reduces the size of the jar to about 7 MB and works fine (at least for the basic example). Nevertheless I get warnings:
Warning: Could not load ...: java.lang.UnsatisfiedLinkError: no jnijavacpp in java.library.path: ...
比较这两个罐子,我发现小罐子缺少所有 so
库以及标头,cmake和pkgconfig文件的 lib
路径,我认为这是警告的原因.
Comparing the two jars I found that the small jar lacks the lib
path with all the so
libs along with header, cmake and pkgconfig files and I assume that this is the reason for the warnings.
所以我的问题是:
- 如果显然不需要这些文件来运行jar,为什么要正常包含它们?
- 如何在保持罐子尺寸小的同时防止这些警告?
当然也欢迎采用其他任何方式构建仅具有一个平台所需依赖项的jar.
Any other way to build a jar with just the required dependencies for one platform is of course also welcomed.
推荐答案
我将不得不对该指南进行一些更新,感谢您的举报!现在我们还需要 javacpp-platform
,在这种情况下,这将为 windows-x86_64
提供类似的信息:
I'll have to update that guide a little bit, thanks for reporting! We now also need javacpp-platform
, which would give us something like this for windows-x86_64
in this case:
dependencies {
implementation group: 'org.bytedeco', name: 'tesseract', version: '4.1.1-1.5.3'
implementation group: 'org.bytedeco', name: 'tesseract', version: '4.1.1-1.5.3', classifier: 'windows-x86_64'
implementation group: 'org.bytedeco', name: 'leptonica', version: '1.79.0-1.5.3', classifier: 'windows-x86_64'
implementation group: 'org.bytedeco', name: 'javacpp', version: '1.5.3', classifier: 'windows-x86_64'
}
这是解决加载时某些问题的必要方法,如本期所述:
https://github.com/bytedeco/javacv/issues/1305
This is needed to fix some issues at load time as explained in this issue:
https://github.com/bytedeco/javacv/issues/1305
更新:现在可以使用 Gradle JavaCPP 来更轻松地做到这一点:
UPDATE: It's now possible to use Gradle JavaCPP to do this more easily this way:
plugins {
id 'java-library'
id 'org.bytedeco.gradle-javacpp-platform' version "$javacppVersion"
}
// We can set this on the command line too this way: -PjavacppPlatform=linux-x86_64,macosx-x86_64,windows-x86_64,etc
ext {
javacppPlatform = 'linux-x86_64,macosx-x86_64,windows-x86_64,etc' // defaults to Loader.getPlatform()
}
dependencies {
api "org.bytedeco:tesseract-platform:$tesseractVersion"
}
这篇关于仅使用必需平台的二进制文件来构建jar(javacpp)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!