1 25 26 package org.objectweb.jonas.server; 27 28 import java.lang.reflect.InvocationTargetException ; 29 import java.lang.reflect.Method ; 30 31 import org.objectweb.jonas.common.JProp; 32 33 40 public class Bootstrap { 41 42 45 private static final String JONAS_SERVER_CLASS = "org.objectweb.jonas.server.Server"; 46 47 50 private static final String REQUIRED_JVM_VERSION = "1.4"; 51 52 55 private Bootstrap() { 56 } 57 58 62 public static void main(String [] args) { 63 String classToRun = args[0]; 64 65 String specVersion = System.getProperty("java.specification.version"); 67 if (specVersion.compareTo(REQUIRED_JVM_VERSION) < 0) { 68 String implVersion = System.getProperty("java.vm.version"); 69 System.err.println("A '" + REQUIRED_JVM_VERSION + "' JVM version or higher is required for JOnAS. Current JVM implementation version is '" 70 + implVersion + "' with specification '" + specVersion + "'"); 71 System.exit(0); 72 } 73 74 try { 75 76 LoaderManager lm = LoaderManager.getInstance(); 77 lm.init(JProp.getInstance()); 78 JClassLoader jonasLoader = null; 79 80 if (classToRun.equals(JONAS_SERVER_CLASS)) { 82 jonasLoader = lm.getAppsLoader(); 83 } else { 84 jonasLoader = lm.getToolsLoader(); 85 } 86 87 Thread.currentThread().setContextClassLoader(jonasLoader); 88 89 91 Class clazz = jonasLoader.loadClass(classToRun); 93 Class [] argList = new Class [] {args.getClass()}; 94 Method meth = clazz.getMethod("main", argList); 95 String [] newArgs = new String [args.length - 1]; 96 System.arraycopy(args, 1, newArgs, 0, newArgs.length); 97 meth.invoke(null, new Object [] {newArgs}); 98 } catch (InvocationTargetException ite) { 99 Throwable t = ite.getTargetException(); 100 String message = t.getMessage(); 101 if (t instanceof Error ) { 102 System.err.println("Error during execution of " + classToRun + " : " + message); 103 } else if (t instanceof Exception ) { 104 System.err.println("Exception during execution of " + classToRun + " : " + message); 105 } 106 t.printStackTrace(System.err); 107 System.exit(2); 108 } catch (Exception e) { 109 System.err.println(classToRun + " reflection error : " + e); 110 e.printStackTrace(); 111 System.exit(2); 112 } 113 } 114 } | Popular Tags |