javaclass

runclass.py

161:b3d6020a2737
2005-01-24 Paul Boddie Reformatted and added a note about the memory issue in the test program.
     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 # NOTE: Simple __this__ package loader to potentially avoid repeated import     9 # NOTE: issues exposed by test.py.    10     11 def load_classes(class_names):    12     13     "Load the classes with the given 'class_names'."    14     15     module = __import__("__this__", globals(), locals(), class_names)    16     objs = []    17     for class_name in class_names:    18         objs.append(getattr(module, class_name))    19     return objs    20     21 # The more general class loader.    22     23 def load_class(class_name):    24     25     "Load the class with the given 'class_name'."    26     27     class_name_parts = class_name.split(".")    28     if len(class_name_parts) == 1:    29         module = __import__("__this__", globals(), locals(), [class_name])    30         obj = getattr(module, class_name)    31     else:    32         class_module = ".".join(class_name_parts[:-1])    33         obj = __import__(class_module, globals(), locals())    34         for part in class_name_parts[1:]:    35             obj = getattr(obj, part)    36     37     return obj    38     39 def run_class(cls, args):    40     cls.main([java.lang.String(arg) for arg in args])    41     42 if __name__ == "__main__":    43     import sys    44     cls = load_class(sys.argv[1])    45     run_class(cls, sys.argv[2:])    46     47 # vim: tabstop=4 expandtab shiftwidth=4