Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- import py4j.java_gateway import JavaGateway
- def start_java():
- # Note: I assume that my_library.jar contains the library you want to expose with your CLI program.
- ARGS = ['java', '-cp', '/path/to/my_library.jar:/path/to/my/class_dir:/path/to/py4j-java.jar', 'p1.MyApplication']
- p = subprocess.Popen(ARGS)
- print('Java Started: {0}'.format(p.pid))
- def stop_java():
- gateway = JavaGateway()
- gateway.shutdown()
- # Two alternatives:
- # (1) You could call a method on the Java side that calls System.exit(0);
- # (2) You could save the pid from start_java and kill the process, but you need to handle mac, linux, and
- # windows...
Add Comment
Please, Sign In to add comment