Skip to content

Commit 88fe268

Browse files
authored
Merge pull request #1180 from sappo/master
Include native libraries in JNI jar (linux only)
2 parents 63cce45 + d34a489 commit 88fe268

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

zproject_java.gsl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,17 @@ task initCMake(type: Exec, dependsOn: 'generateJniHeaders') {
181181
task buildNative(type: Exec, dependsOn: 'initCMake') {
182182
commandLine "make"
183183
}
184+
185+
task copyLibs(type: Copy) {
186+
from "/usr/lib/$(project.libname).so", "/usr/local/lib/$(project.libname).so", "/tmp/lib/$(project.libname).so",
187+
. for project.use
188+
"/usr/lib/$(use.libname).so", "/usr/local/lib/$(use.libname).so", "/tmp/lib/$(use.libname).so"$(last ()?? ""? ",")
189+
. endfor
190+
into "."
191+
}
192+
184193
jar.dependsOn buildNative
194+
jar.dependsOn copyLibs
185195
test.dependsOn buildNative
186196

187197
jar {
@@ -259,7 +269,7 @@ bintray {
259269

260270
clean.doFirst {
261271
delete "${rootDir}/CMakeCache.txt"
262-
delete "${rootDir}/libczmqjni.so"
272+
delete fileTree("${rootDir}") { include "*.so" }
263273
}
264274
.
265275
.output "$(topdir)/README.md"
@@ -770,6 +780,14 @@ implements AutoCloseable\
770780
System.loadLibrary("$(project.prefix:c)jni");
771781
} else {
772782
try {
783+
. for project.use
784+
NativeLoader.loadLibrary("$(use.prefix:c)");
785+
. endfor
786+
NativeLoader.loadLibrary("$(project.prefix:c)");
787+
} catch (Exception e) {
788+
System.err.println("[WARN] " + e.getMessage() +" from jar. Assuming it is installed on the system.");
789+
}
790+
try {
773791
NativeLoader.loadLibrary("$(project.prefix:c)jni");
774792
} catch (Exception e) {
775793
System.exit (-1);

0 commit comments

Comments
 (0)