1 package org.sapia.magnet.domain.java; 2 3 import java.lang.reflect.Method ; 6 import java.lang.reflect.InvocationTargetException ; 7 8 9 20 public class JavaTask implements Runnable { 21 22 26 27 private Class _theMainClass; 28 29 30 private String [] _theArguments; 31 32 36 39 public JavaTask(Class aMainClas, String [] someArguments) { 40 _theMainClass = aMainClas; 41 _theArguments = someArguments; 42 } 43 44 47 public void run() { 48 try { 49 Method aMainMethod = _theMainClass.getDeclaredMethod("main", new Class [] { String [].class }); 50 aMainMethod.invoke(_theMainClass, new Object [] { _theArguments }); 51 } catch (NoSuchMethodException nsme) { 52 throw new RuntimeException ("main method not found on class " + _theMainClass.getName() + 53 " - " + nsme.getMessage()); 54 } catch (InvocationTargetException ite) { 55 throw new RuntimeException ("Error calling main method on class " + _theMainClass.getName() + 56 " - " + ite.getTargetException().getMessage()); 57 } catch (IllegalAccessException iae) { 58 throw new RuntimeException ("main method was found but is not accessible on class " + _theMainClass.getName() + 59 " - " + iae.getMessage()); 60 } 61 } 62 } 63 64 | Popular Tags |