001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: Bootstrap.java 6366 2005-03-04 13:08:15Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.server;
025:
026: import java.lang.reflect.InvocationTargetException;
027: import java.lang.reflect.Method;
028:
029: import org.objectweb.jonas.common.JProp;
030:
031: /**
032: * This class load all the jars needed to start JOnAS and after this, it launch
033: * the JOnAS server (Server class).
034: * @author Ludovic Bert (initial developer)
035: * @author Florent Benoit (initial developer)
036: * @author Philippe Durieux (new jonas jar files architecture)
037: */
038: public class Bootstrap {
039:
040: /**
041: * Server class name
042: */
043: private static final String JONAS_SERVER_CLASS = "org.objectweb.jonas.server.Server";
044:
045: /**
046: * Required JVM version
047: */
048: private static final String REQUIRED_JVM_VERSION = "1.4";
049:
050: /**
051: * Empty, private Constructor for Utility Class
052: */
053: private Bootstrap() {
054: }
055:
056: /**
057: * Server main routine (Load all the jars needed to start jonas)
058: * @param args the list of the args to give to the bootstrap class.
059: */
060: public static void main(String[] args) {
061: String classToRun = args[0];
062:
063: // JDK 1.4 or higher is required
064: String specVersion = System
065: .getProperty("java.specification.version");
066: if (specVersion.compareTo(REQUIRED_JVM_VERSION) < 0) {
067: String implVersion = System.getProperty("java.vm.version");
068: System.err
069: .println("A '"
070: + REQUIRED_JVM_VERSION
071: + "' JVM version or higher is required for JOnAS. Current JVM implementation version is '"
072: + implVersion + "' with specification '"
073: + specVersion + "'");
074: System.exit(0);
075: }
076:
077: try {
078:
079: LoaderManager lm = LoaderManager.getInstance();
080: lm.init(JProp.getInstance());
081: JClassLoader jonasLoader = null;
082:
083: // TODO : Can specify classloader to use ?
084: if (classToRun.equals(JONAS_SERVER_CLASS)) {
085: jonasLoader = lm.getAppsLoader();
086: } else {
087: jonasLoader = lm.getToolsLoader();
088: }
089:
090: Thread.currentThread().setContextClassLoader(jonasLoader);
091:
092: //jonasLoader.printURLs(); // DEBUG
093:
094: // Launch the "class_to_run" by using our classloader.
095: Class clazz = jonasLoader.loadClass(classToRun);
096: Class[] argList = new Class[] { args.getClass() };
097: Method meth = clazz.getMethod("main", argList);
098: String[] newArgs = new String[args.length - 1];
099: System.arraycopy(args, 1, newArgs, 0, newArgs.length);
100: meth.invoke(null, new Object[] { newArgs });
101: } catch (InvocationTargetException ite) {
102: Throwable t = ite.getTargetException();
103: String message = t.getMessage();
104: if (t instanceof Error) {
105: System.err.println("Error during execution of "
106: + classToRun + " : " + message);
107: } else if (t instanceof Exception) {
108: System.err.println("Exception during execution of "
109: + classToRun + " : " + message);
110: }
111: t.printStackTrace(System.err);
112: System.exit(2);
113: } catch (Exception e) {
114: System.err.println(classToRun + " reflection error : " + e);
115: e.printStackTrace();
116: System.exit(2);
117: }
118: }
119: }
|