-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjavafromfile
executable file
·42 lines (34 loc) · 1.18 KB
/
javafromfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
import sys, os
from pathlib import Path
# Run Java from a file instead of a Java class. This is intended to let
# you use standard shell completion instead of typing long Java class names.
# This assumes that $CLASSPATH is set.
# Author: David McClosky
# Homepage: http://zorglish.org
# Code: http://github.com/dmcc
java = os.getenv('JAVA', 'java') # let people override the Java binary with $JAVA
args = sys.argv[1:]
jvm_args = []
while 1:
top = args[0]
if top.startswith('-'):
jvm_args.append(args.pop(0))
else:
break
filename = Path(args.pop(0))
if not filename.exists():
raise SystemExit("File %s doesn't exist." % filename)
package = None
for line in open(filename):
line = line.strip()
if line.startswith('package') and line.endswith(';'):
# e.g. "package edu.stanford.nlp.annotation;"
package = line.split()[1][:-1]
break
if not package:
raise SystemExit("Couldn't find Java package in %s" % filename)
classname = package + '.' + Path(filename.name).stem
command = ' '.join([java] + jvm_args + [classname] + args)
print('{}: running {!r}'.format(sys.argv[0], command), file=sys.stderr)
os.system(command)