1 5 package ve.luz.ica.jackass.daemon; 6 7 import java.io.File ; 8 import java.lang.reflect.Method ; 9 import java.net.URL ; 10 import java.net.URLClassLoader ; 11 12 import org.apache.commons.logging.Log; 13 import org.apache.commons.logging.LogFactory; 14 15 19 class NameServiceThread extends Thread 20 { 21 private static final Log LOG = LogFactory.getLog(NameServiceThread.class); 22 private static final String MAIN_METHOD = "main"; 23 24 private String className = null; 25 private String [] commandLineParams = null; 26 27 32 public NameServiceThread(String name, String [] params) 33 { 34 this.className = name; 35 this.commandLineParams = params; 36 } 37 38 41 public void run() 42 { 43 Class [] params = {String [].class}; 44 Class nsClass; 45 try 46 { 47 File file = new File (className); 48 49 if (LOG.isDebugEnabled()) LOG.debug("loading " + file.getPath()); 50 51 URL [] urls = {file.toURL()}; 52 URLClassLoader loader = new URLClassLoader (urls); 53 54 nsClass = Class.forName(className, true, loader); 55 Method mainMethod = nsClass.getDeclaredMethod(MAIN_METHOD, params); 56 mainMethod.invoke(null, new Object [] {commandLineParams}); 57 } 58 catch (Exception e) 59 { 60 LOG.error("Error starting the name service", e); 61 } 62 } 63 64 } 65 | Popular Tags |