Created
March 20, 2020 03:39
-
-
Save aoirint/213f2f6d65ae383f587db1ef3d7c2204 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import sys | |
| import io | |
| import subprocess | |
| import argparse | |
| JAVA_HOME = '/usr/lib/jvm/java-11-openjdk-amd64' | |
| JDEPS = os.path.join(JAVA_HOME, 'bin/jdeps') | |
| JLINK = os.path.join(JAVA_HOME, 'bin/jlink') | |
| JMODS_DIR = os.path.join(JAVA_HOME, 'jmods') | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('target_jar_path', type=str) | |
| parser.add_argument('jre_out_path', type=str) | |
| args = parser.parse_args() | |
| target_jar_path = args.target_jar_path | |
| jre_out_path = args.jre_out_path | |
| print('Resolving dependencies..') | |
| jdeps_cmd = [ JDEPS, '--list-deps', target_jar_path ] | |
| proc = subprocess.run(jdeps_cmd, capture_output=True) | |
| if proc.returncode != 0: | |
| print('error') | |
| sys.exit(1) | |
| jdeps_out = proc.stdout.decode('utf-8').strip() | |
| required_modules = [] | |
| for line in jdeps_out.split('\n'): | |
| required_modules.append(line.strip()) | |
| print('# Required Module List') | |
| print(required_modules) | |
| print('Creating JRE..') | |
| modules = ','.join(required_modules) | |
| jlink_cmd = [ JLINK, '--compress=2', '--module-path', JMODS_DIR, '--add-modules', modules, '--output', jre_out_path ] | |
| proc = subprocess.run(jlink_cmd) | |
| if proc.returncode != 0: | |
| print('error') | |
| sys.exit(1) | |
| print('Done.') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment