KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > server > SnipSnapLauncher


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

25 package org.snipsnap.server;
26
27 import java.io.File JavaDoc;
28 import java.io.FileOutputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.io.PrintStream JavaDoc;
31
32 /**
33  * SnipSnap launcher that takes care of adding the compiler to the classpath before
34  * invoking AppServer.
35  *
36  * @author Matthias L. Jugel
37  * @version $Id: SnipSnapLauncher.java 1712 2004-07-14 11:20:59Z leo $
38  */

39 public class SnipSnapLauncher extends Launcher {
40
41   /**
42    * Start SnipSnap after adding the sdk tools.jar or similar to the classpath.
43    *
44    * @param args command line arguments
45    */

46   public static void main(String JavaDoc[] args) {
47     // try to add the java compiler path
48
File JavaDoc toolsJar = new File JavaDoc(new File JavaDoc(System.getProperty("java.home")), "lib/tools.jar");
49     if (!toolsJar.exists()) {
50       toolsJar = new File JavaDoc(new File JavaDoc(System.getProperty("java.home")), "../lib/tools.jar");
51     }
52     if (!toolsJar.exists()) {
53       String JavaDoc system = System.getProperty("os.name");
54       if (system.startsWith("Mac OS X")) {
55         toolsJar = new File JavaDoc("/System/Library/Frameworks/JavaVM.framework/Classes/classes.jar");
56       } else {
57         System.out.println("Java SDK not found: " + toolsJar);
58         System.out.println("Please set JAVA_HOME to the SDK home directory.");
59         System.out.println("SnipSnap will run, but you cannot use source JSP files.");
60       }
61     }
62     try {
63       System.setProperty(Launcher.CLASSPATH, toolsJar.getCanonicalPath());
64     } catch (IOException JavaDoc e) {
65       System.out.println("SnipSnapLauncher: unable to add java compiler library: " + e.getMessage());
66     }
67
68     try {
69       File JavaDoc errorLog = null;
70       if (System.getProperty("launcher.errlog") != null) {
71         errorLog = new File JavaDoc(System.getProperty("launcher.errlog"));
72       } else {
73         errorLog = File.createTempFile("snipsnap_", ".log");
74       }
75       System.err.println("Launcher: System.err redirected to " + errorLog.getPath());
76       System.setErr(new PrintStream JavaDoc(new FileOutputStream JavaDoc(errorLog)));
77     } catch (IOException JavaDoc e) {
78       System.err.println("Launcher: unable to redirect error log: " + e.getMessage());
79     }
80
81     try {
82       invokeMain("org.snipsnap.server.AppServer", args);
83     } catch (Exception JavaDoc e) {
84       System.out.println("SnipSnapLauncher: unable to start server: " + e.getMessage());
85       e.printStackTrace();
86     }
87   }
88 }
Popular Tags