Skip to content

Commit

Permalink
Add Java process lookup for 'java.home' in find_jvm_dll_file() (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinrsmith authored Sep 26, 2022
1 parent e1c13bd commit b16180c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions jpyutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit b16180c

Please sign in to comment.