1 23 24 package com.rift.coad; 26 27 import java.util.StringTokenizer ; 29 import java.io.File ; 30 import java.util.Vector ; 31 import java.net.URL ; 32 import java.lang.reflect.Method ; 33 import java.net.URLClassLoader ; 34 35 40 public class Main { 41 42 47 public static void main(String [] args) { 48 try { 49 String libdirs = System.getenv("COAD_LIB_DIRS"); 50 StringTokenizer stringTok = null; 51 if (libdirs.contains(";")) { 52 stringTok = new StringTokenizer (libdirs,";"); 53 System.out.println("Contains ;"); 54 } else { 55 stringTok = new StringTokenizer (libdirs,":"); 56 System.out.println("Contains :"); 57 } 58 System.out.println("Load from path : " + 59 System.getenv("COAD_LIB_DIRS")); 60 Vector urls = new Vector (); 61 while(stringTok.hasMoreTokens()) { 62 String dirPath = stringTok.nextToken(); 63 File dir = new File (dirPath); 64 if (dir.isFile() == true) { 65 System.out.println( 66 "Add File [" + dir.toString() + "]"); 67 urls.add(dir.toURL()); 68 continue; 69 } 70 if (dir.isDirectory() == false) { 71 System.out.println("The path [" + dirPath 72 + "] does not point at a valid directory."); 73 System.exit(-1); 74 } 75 File [] files = dir.listFiles(); 76 for (int index = 0; index < files.length; index++) { 77 String filePath = files[index].getAbsolutePath(); 78 if (filePath.endsWith(".jar") || filePath.endsWith(".zip")) { 79 System.out.println( 80 "Add File [" + filePath + "]"); 81 urls.add(files[index].toURL()); 82 } 83 } 84 } 85 URL [] urlArray = new URL [urls.size()]; 86 urls.toArray(urlArray); 87 BaseClassLoader baseClassLoader = new BaseClassLoader(urlArray, 88 Main.class.getClassLoader()); 89 Class classRef = baseClassLoader.loadClass("com.rift.coad.Runner"); 90 if (classRef == null) { 91 System.out.println( 92 "Failed to run the Coadunation base Runner reference " + 93 "is null."); 94 throw new Exception ("Failed to retrieve the appropriate class " + 95 "reference to start coadunation."); 96 } 97 System.out.println("Start Coadunation"); 98 Method method = classRef.getMethod("main"); 99 System.out.println("Invoking Coadunation"); 100 Thread.currentThread().setContextClassLoader(baseClassLoader); 103 method.invoke(null); 104 105 } catch (Exception ex) { 106 System.out.println("Failed to run the Coadunation base [" + 107 ex.getMessage() + "]"); 108 ex.printStackTrace(System.out); 109 System.exit(-1); 110 } 111 } 112 113 } 114 | Popular Tags |