Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor JAVA_HOME when it is set #34313

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions sdks/python/apache_beam/utils/subprocess_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,23 +274,36 @@ def __init__(
java_arguments,
classpath=None,
cache_dir=None):
java_path = 'java'
java_home = os.environ.get('JAVA_HOME')
if java_home:
java_path = os.path.join(java_home, 'bin', 'java')
self._java_path = java_path
if classpath:
# java -jar ignores the classpath, so we make a new jar that embeds
# the requested classpath.
path_to_jar = self.make_classpath_jar(path_to_jar, classpath, cache_dir)
super().__init__(
stub_class, ['java', '-jar', path_to_jar] + list(java_arguments))
stub_class,
[self._java_path, '-jar', path_to_jar] + list(java_arguments))
self._existing_service = path_to_jar if is_service_endpoint(
path_to_jar) else None

def start_process(self):
if self._existing_service:
return None, self._existing_service
else:
if not shutil.which('java'):
raise RuntimeError(
'Java must be installed on this system to use this '
'transform/runner.')
if not shutil.which(self._java_path):
java_home = os.environ.get('JAVA_HOME')
if java_home:
raise RuntimeError(
'Java is not correctly installed in JAVA_HOME=%s to use this '
'transform/runner. Please check if JAVA_HOME is correctly set and'
' points to your Java installation directory.' % java_home)
else:
raise RuntimeError(
'Java must be installed on this system to use this '
'transform/runner.')
return super().start_process()

def stop_process(self):
Expand Down
Loading