KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > standalone > BlogunityServer


1 /*
2  * $Id: BlogunityServer.java,v 1.3 2004/12/26 12:39:50 michelson Exp $
3  *
4  * Copyright (c) 2004 j2biz Group, http://www.j2biz.com Koeln / Duesseldorf ,
5  * Germany
6  *
7  * @author Max Kalina
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License as published by the Free Software
12  * Foundation; either version 2 of the License, or (at your option) any later
13  * version.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License along with
21  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  * Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */

25
26 package com.j2biz.blogunity.standalone;
27
28 import java.io.File JavaDoc;
29 import java.io.FileInputStream JavaDoc;
30 import java.util.Properties JavaDoc;
31
32 import org.mortbay.http.SocketListener;
33 import org.mortbay.jetty.Server;
34
35 public class BlogunityServer {
36
37     private static int PORT = 8080;
38
39     private static String JavaDoc CONTEXT_PATH = "/";
40
41     private static String JavaDoc WEBAPP_PATH = "./webapp";
42
43     public static void main(String JavaDoc[] args) {
44
45         try {
46
47             int port = PORT;
48             String JavaDoc ctxpathStr = CONTEXT_PATH;
49             String JavaDoc webapppathStr = WEBAPP_PATH;
50
51             Properties JavaDoc configProps;
52             try {
53                 File JavaDoc config = new File JavaDoc("server.conf");
54                 FileInputStream JavaDoc in = new FileInputStream JavaDoc(config);
55                 configProps = new Properties JavaDoc();
56                 configProps.load(in);
57                 in.close();
58
59                 String JavaDoc portStr = configProps.getProperty("port");
60                 if (portStr != null && portStr.trim().length() > 0) {
61                     try {
62                         port = Integer.parseInt(portStr);
63                     } catch (RuntimeException JavaDoc e1) {
64                         port = PORT;
65                     }
66                 }
67
68                 ctxpathStr = configProps.getProperty("contextPath");
69                 if (ctxpathStr == null || ctxpathStr.trim().length() <= 0)
70                         ctxpathStr = CONTEXT_PATH;
71
72                 webapppathStr = configProps.getProperty("webappPath");
73                 if (webapppathStr == null || webapppathStr.trim().length() <= 0)
74                         webapppathStr = WEBAPP_PATH;
75
76             } catch (Exception JavaDoc e2) {
77             }
78
79             
80             System.out.println("************************************");
81             System.out.println("* Starting Blogunity-Standalone *");
82             System.out.println("* Powered by Jetty HTTP-Server *");
83             System.out.println("************************************");
84             System.out.println("\nIf this is your first time starting standalone distribution,");
85             System.out.println("please login as user 'admin' with password 'admin' into system");
86             System.out.println("and change for safety reasons this login informations immediately.");
87             
88             
89             Server server = new Server();
90             SocketListener listener = new SocketListener();
91             listener.setPort(port);
92             server.addListener(listener);
93
94             server.addWebApplication(ctxpathStr, webapppathStr);
95             server.start();
96         } catch (Exception JavaDoc e) {
97             e.printStackTrace();
98         }
99
100     }
101 }
Popular Tags