KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > server > Bootstrap


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: Bootstrap.java,v 1.52 2005/03/04 13:08:15 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.server;
27
28 import java.lang.reflect.InvocationTargetException JavaDoc;
29 import java.lang.reflect.Method JavaDoc;
30
31 import org.objectweb.jonas.common.JProp;
32
33 /**
34  * This class load all the jars needed to start JOnAS and after this, it launch
35  * the JOnAS server (Server class).
36  * @author Ludovic Bert (initial developer)
37  * @author Florent Benoit (initial developer)
38  * @author Philippe Durieux (new jonas jar files architecture)
39  */

40 public class Bootstrap {
41
42     /**
43      * Server class name
44      */

45     private static final String JavaDoc JONAS_SERVER_CLASS = "org.objectweb.jonas.server.Server";
46
47     /**
48      * Required JVM version
49      */

50     private static final String JavaDoc REQUIRED_JVM_VERSION = "1.4";
51
52     /**
53      * Empty, private Constructor for Utility Class
54      */

55     private Bootstrap() {
56     }
57
58     /**
59      * Server main routine (Load all the jars needed to start jonas)
60      * @param args the list of the args to give to the bootstrap class.
61      */

62     public static void main(String JavaDoc[] args) {
63         String JavaDoc classToRun = args[0];
64
65         // JDK 1.4 or higher is required
66
String JavaDoc specVersion = System.getProperty("java.specification.version");
67         if (specVersion.compareTo(REQUIRED_JVM_VERSION) < 0) {
68             String JavaDoc 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             // TODO : Can specify classloader to use ?
81
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             //jonasLoader.printURLs(); // DEBUG
90

91             // Launch the "class_to_run" by using our classloader.
92
Class JavaDoc clazz = jonasLoader.loadClass(classToRun);
93             Class JavaDoc[] argList = new Class JavaDoc[] {args.getClass()};
94             Method JavaDoc meth = clazz.getMethod("main", argList);
95             String JavaDoc[] newArgs = new String JavaDoc[args.length - 1];
96             System.arraycopy(args, 1, newArgs, 0, newArgs.length);
97             meth.invoke(null, new Object JavaDoc[] {newArgs});
98         } catch (InvocationTargetException JavaDoc ite) {
99             Throwable JavaDoc t = ite.getTargetException();
100             String JavaDoc message = t.getMessage();
101             if (t instanceof Error JavaDoc) {
102                 System.err.println("Error during execution of " + classToRun + " : " + message);
103             } else if (t instanceof Exception JavaDoc) {
104                 System.err.println("Exception during execution of " + classToRun + " : " + message);
105             }
106             t.printStackTrace(System.err);
107             System.exit(2);
108         } catch (Exception JavaDoc e) {
109             System.err.println(classToRun + " reflection error : " + e);
110             e.printStackTrace();
111             System.exit(2);
112         }
113     }
114 }
Popular Tags