?? main.java
字號(hào):
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package com.dreambean.dynaserver;
import java.io.*;
import java.net.*;
import java.util.*;
/**
* Wrapper for DynaServer which is used for the executable jar.
* Reads dynaserver.properties and system properties to configure DynaServer before starting
*
* @author $Author: Rickard 謆erg$
* @version $Revision: 1.0$
*/
public class Main
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
public static void main(String[] args)
throws Exception
{
new Main();
}
// Constructors --------------------------------------------------
public Main()
throws IOException
{
// Create server
DynaServer srv = new DynaServer();
// Load configuration
Properties cfg = loadConfiguration();
// Set configuration
srv.setPort(Integer.parseInt(cfg.getProperty("dynaserver.port")));
srv.setBackLog(Integer.parseInt(cfg.getProperty("dynaserver.backlog")));
srv.setDebug(new Boolean(cfg.getProperty("dynaserver.debug")).booleanValue());
// Add optional classloader
String urls = cfg.getProperty("dynaserver.urls");
if (urls != null)
{
srv.debug("Adding classloader with URLS:"+urls);
StringTokenizer urlTokens = new StringTokenizer(urls, " "); // Use space as separator
ArrayList urlList = new ArrayList();
while (urlTokens.hasMoreTokens())
{
String url = urlTokens.nextToken();
try
{
urlList.add(new URL(url));
} catch (MalformedURLException e)
{
try
{
// Try as file
File f = new File(url);
if (f.exists())
urlList.add(f.toURL());
else
throw new MalformedURLException("No such file/directory");
} catch (MalformedURLException exc)
{
srv.debug("Malformed URL:"+url+"("+exc.getMessage()+")");
}
}
}
URL[] urlArray = new URL[urlList.size()];
urlArray = (URL[])urlList.toArray(urlArray);
URLClassLoader cl = new URLClassLoader(urlArray);
srv.addClassLoader(cl);
}
// Start
srv.start();
srv.debug("DynaServer started");
}
// Protected -----------------------------------------------------
protected Properties loadConfiguration()
throws IOException
{
// Load defaults
Properties cfg = new Properties(System.getProperties());
try
{
cfg.load(getClass().getResourceAsStream("/dynaserver.default"));
} catch (Exception e)
{
e.printStackTrace(System.err);
}
// Load overriding config
cfg = new Properties(cfg);
try
{
InputStream in = getClass().getResourceAsStream("/dynaserver.properties");
if (in != null)
cfg.load(in);
} catch (Exception e)
{
e.printStackTrace(System.err);
}
return cfg;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -