1
+ #!/usr/bin/env python3
2
+
1
3
# CDDL HEADER START
2
4
#
3
5
# The contents of this file are subject to the terms of the
25
27
from utils import is_exe
26
28
import os
27
29
import argparse
30
+ import sys
31
+ import logging
28
32
29
33
30
34
class Java (Command ):
@@ -77,7 +81,7 @@ def FindJava(self, logger):
77
81
elif system_name == 'Darwin' :
78
82
cmd = Command ('/usr/libexec/java_home' )
79
83
cmd .execute ()
80
- java = cmd .getoutputstr ()
84
+ java = os . path . join ( cmd .getoutputstr (), 'bin' , 'java' )
81
85
elif system_name == 'Linux' :
82
86
link_path = '/etc/alternatives/java'
83
87
if os .path .exists (link_path ):
@@ -95,8 +99,40 @@ def get_javaparser():
95
99
help = 'path to java binary' )
96
100
parser .add_argument ('-J' , '--java_opts' ,
97
101
help = 'java options' , action = 'append' )
98
- parser .add_argument ('-a' , '--jar' , required = True ,
99
- help = 'Path to jar archive to run' )
102
+
103
+ group = parser .add_mutually_exclusive_group (required = True )
104
+ group .add_argument ('-a' , '--jar' ,
105
+ help = 'Path to jar archive to run' )
106
+ group .add_argument ('-c' , '--classpath' ,
107
+ help = 'Class path' )
108
+
100
109
parser .add_argument ('options' , nargs = '+' , help = 'options' )
101
110
102
111
return parser
112
+
113
+
114
+ if __name__ == '__main__' :
115
+
116
+ parser = argparse .ArgumentParser (description = 'java wrapper' ,
117
+ parents = [get_javaparser ()])
118
+ parser .add_argument ('-m' , '--mainclass' , required = True ,
119
+ help = 'Main class' )
120
+
121
+ args = parser .parse_args ()
122
+
123
+ if args .debug :
124
+ logging .basicConfig (level = logging .DEBUG )
125
+ else :
126
+ logging .basicConfig ()
127
+
128
+ logger = logging .getLogger (os .path .basename (sys .argv [0 ]))
129
+
130
+ java = Java (args .options , logger = logger , java = args .java ,
131
+ jar = args .jar , java_opts = args .java_opts ,
132
+ classpath = args .classpath , main_class = args .mainclass )
133
+ java .execute ()
134
+ ret = java .getretcode ()
135
+ if ret is None or ret != 0 :
136
+ logger .error (java .getoutputstr ())
137
+ logger .error ("java command failed (return code {})" .format (ret ))
138
+ sys .exit (1 )
0 commit comments