From 764e033bf407ee9219ed1239b8f8599ba935c364 Mon Sep 17 00:00:00 2001 From: Karlheinz Friedberger Date: Fri, 13 Aug 2021 23:54:02 +0200 Subject: [PATCH] Specify and document value for environment variable for loading native library in Java bindings (#5477) * limit range of environment variable for loading the native library in Java to "true". This change specifies the range of values that are allowed to set the environment variable "z3.skipLibraryLoad". Only the value "true" (in upper-, lower-, and mixed-case is accepted as valid value. Other values, such as "false", "0", "1", "foo", an empty or a missing value are evaluated to "false" and cause the default loading of the native library. * adding documentation about environment variable for (not) loading the native library in Java. This is a follow-up commit for #4667 to provide a publicly visible documentation. --- examples/java/README | 6 ++++++ scripts/update_api.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/java/README b/examples/java/README index d3ff93fe099..3d980feeb77 100644 --- a/examples/java/README +++ b/examples/java/README @@ -12,3 +12,9 @@ On Linux and FreeBSD, we must use LD_LIBRARY_PATH=. java -cp com.microsoft.z3.jar:. JavaExample On macOS, the corresponding option is DYLD_LIBRARY_PATH: DYLD_LIBRARY_PATH=. java -cp com.microsoft.z3.jar:. JavaExample + +By default, Z3 Java bindings are automatically loading the required native library for Z3 from the default library path. +In certain environments, depending on the developing process, the Z3 library is not available in the given library path. +To disable the automated loading process, the user can set the environment variable "z3.skipLibraryLoad=true". +In that case, the calling application should directly load the corresponding libraries before any interaction with Z3. + diff --git a/scripts/update_api.py b/scripts/update_api.py index 56ef503e9a0..5095241598c 100755 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -545,7 +545,7 @@ def mk_java(java_dir, package_name): java_native.write(' public static native void setInternalErrorHandler(long ctx);\n\n') java_native.write(' static {\n') - java_native.write(' if (null == System.getProperty("z3.skipLibraryLoad")) {\n') + java_native.write(' if (!Boolean.parseBoolean(System.getProperty("z3.skipLibraryLoad"))) {\n') java_native.write(' try {\n') java_native.write(' System.loadLibrary("z3java");\n') java_native.write(' } catch (UnsatisfiedLinkError ex) {\n')