javaclass

runclass.py

158:a52e70c3f294
2005-01-23 Paul Boddie Added "safety measures" for exception offset insertion, although better measures are necessary to avoid bizarre JDK 1.4 exception tables.
     1 #!/usr/bin/env python     2      3 "A program to run Java class files."     4      5 import javaclass.classhook     6 import java.lang     7      8 def load_class(class_name):     9     10     "Load the class with the given 'class_name'."    11     12     class_name_parts = class_name.split(".")    13     if len(class_name_parts) == 1:    14         module = __import__("__this__", globals(), locals(), [class_name])    15         obj = getattr(module, class_name)    16     else:    17         class_module = ".".join(class_name_parts[:-1])    18         obj = __import__(class_module, globals(), locals())    19         for part in class_name_parts[1:]:    20             obj = getattr(obj, part)    21     22     return obj    23     24 def run_class(cls, args):    25     cls.main([java.lang.String(arg) for arg in args])    26     27 if __name__ == "__main__":    28     import sys    29     cls = load_class(sys.argv[1])    30     run_class(cls, sys.argv[2:])    31     32 # vim: tabstop=4 expandtab shiftwidth=4