⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 精通RMI 这是RMI的入门基础 特别对刚开始学RMI的同胞们很有帮助
💻 JAVA
字号:
/*
 * 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;
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -