1 23 24 33 34 import java.util.Properties ; 35 import java.io.File ; 36 import java.net.URL ; 37 import java.net.URLClassLoader ; 38 import java.net.MalformedURLException ; 39 import java.util.StringTokenizer ; 40 import java.io.FileNotFoundException ; 41 import java.io.FileInputStream ; 42 import java.util.ArrayList ; 43 import java.lang.reflect.Method ; 44 45 public class PLBootstrap { 46 47 public static String INSTALL_ROOT_PROPERTY_NAME="com.sun.aas.installRoot"; 48 public static String PROCESS_LAUCHER_PROPERTIES_FILE_NAME="processLauncher.properties"; 49 public static String PROCESS_LAUCHER_LIBRARIES="processLauncher.libraries"; 50 public static String PROCESS_LAUCHER_MAIN_CLASS="processLauncher.main.class"; 51 52 53 public static boolean bDebug=false; 54 55 public static void main(String [] args) { 56 57 try { 58 59 Properties props=System.getProperties(); 60 if (bDebug) props.list(System.out); 61 62 String installRoot=System.getProperty(INSTALL_ROOT_PROPERTY_NAME); 65 if (installRoot == null) { 66 System.out.println("ERROR: The System property \"com.sun.aas.installRoot\" has to be set!"); 67 System.exit(1); 68 } 69 70 String appservLibPath=installRoot + File.separator + "lib" + File.separator; 71 if (bDebug) System.out.println("Reading properties from - " + appservLibPath + PROCESS_LAUCHER_PROPERTIES_FILE_NAME); 73 File propertiesFile=new File (appservLibPath + PROCESS_LAUCHER_PROPERTIES_FILE_NAME); 74 if (!propertiesFile.canRead()) { 76 throw new FileNotFoundException (propertiesFile.getPath()); 77 } 78 79 Properties properties=new Properties (); 81 FileInputStream fInput=new FileInputStream (propertiesFile); 82 properties.load(fInput); 83 fInput.close(); 84 85 URL [] classJars=stringToURLArray(appservLibPath, properties.getProperty(PROCESS_LAUCHER_LIBRARIES)); 87 URLClassLoader classLoader=new URLClassLoader (classJars, Thread.currentThread().getContextClassLoader()); 88 89 Class plClass=classLoader.loadClass(properties.getProperty(PROCESS_LAUCHER_MAIN_CLASS)); 91 if (bDebug) System.out.println("classloader = " + classLoader + " - " + plClass.getClassLoader()); 92 93 Method mainMethod=plClass.getDeclaredMethod("bootstrap", new Class []{ String [].class }); 95 mainMethod.invoke(null, new Object []{ args }); 96 97 System.exit(0); 99 100 } catch (Throwable t) { 101 t.printStackTrace(); 102 System.exit(1); 103 104 } 105 } 106 107 108 private static URL [] stringToURLArray(String appservLibPath, String jarList) throws MalformedURLException { 109 110 if (bDebug) System.out.println("jar list - " + jarList); 111 112 if (jarList == null || jarList.equals("")) { 114 return new URL [0]; 115 } 116 117 ArrayList jars=new ArrayList (); 119 StringTokenizer stJars=new StringTokenizer (jarList, ","); 120 URL resultantURL=null; 121 String jarName=null, jarPath=null; 122 while (stJars.hasMoreTokens()) { 123 jarName=stJars.nextToken().trim(); 124 if (bDebug) System.out.println("creating url for - " + jarName); 125 126 if (jarName.startsWith("/")) { 128 jarPath=jarName; 129 } else { 130 jarPath=appservLibPath + jarName; 131 } 132 133 resultantURL=new URL ("file:" + jarPath); 135 if (bDebug) System.out.println("resultant url - " + resultantURL); 136 jars.add(resultantURL); 137 } 138 return (URL [])jars.toArray(new URL [jars.size()]); 139 } 140 141 142 } | Popular Tags |