From b16180c4b225a5c711ded8299188b115ceea3aaf Mon Sep 17 00:00:00 2001 From: Devin Smith Date: Mon, 26 Sep 2022 15:53:46 -0700 Subject: [PATCH] Add Java process lookup for 'java.home' in find_jvm_dll_file() (#89) --- jpyutil.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jpyutil.py b/jpyutil.py index 2c94f909..08efd9ab 100644 --- a/jpyutil.py +++ b/jpyutil.py @@ -160,6 +160,16 @@ def find_jdk_home_dir(): return None +def _java_process_java_home(): + logger.debug('Checking Java for JAVA_HOME...') + try: + from java_utilities import lookup_property + return lookup_property('java.home', use_env=False) + except ImportError: + logger.debug("java_utilities not found, skipping java process check") + except Exception as e: + logger.debug(e, exc_info=True) + return None def find_jvm_dll_file(java_home_dir=None, fail=False): """ @@ -188,6 +198,12 @@ def find_jvm_dll_file(java_home_dir=None, fail=False): if jvm_dll_path: return jvm_dll_path + java_home_dir = _java_process_java_home() + if java_home_dir: + jvm_dll_path = _find_jvm_dll_file(java_home_dir) + if jvm_dll_path: + return jvm_dll_path + jvm_dll_path = ctypes.util.find_library(JVM_LIB_NAME) if jvm_dll_path: logger.debug("No JVM shared library file found in all search paths. Using fallback %s" % repr(jvm_dll_path))