1 25 26 package org.objectweb.easybeans.server; 27 28 import java.net.URL ; 29 30 import org.objectweb.easybeans.log.JLog; 31 import org.objectweb.easybeans.log.JLogFactory; 32 33 37 public final class EasyBeans { 38 39 42 public static final String DEFAULT_XML_FILE = "org/objectweb/easybeans/server/easybeans-default.xml"; 43 44 47 public static final String USER_XML_FILE = "easybeans.xml"; 48 49 52 private static JLog logger = JLogFactory.getLog(EasyBeans.class); 53 54 57 private EasyBeans() { 58 59 } 60 61 66 public static void main(final String [] args) throws Exception { 67 68 Embedded embedded = null; 69 70 URL xmlConfigurationURL = Thread.currentThread().getContextClassLoader().getResource(USER_XML_FILE); 72 73 if (xmlConfigurationURL == null) { 74 logger.warn("No user-defined configuration file named {0} found in classpath, use default settings", USER_XML_FILE); 75 xmlConfigurationURL = Thread.currentThread().getContextClassLoader().getResource(DEFAULT_XML_FILE); 76 } 77 try { 78 embedded = EmbeddedConfigurator.create(xmlConfigurationURL); 79 } catch (EmbeddedException e) { 80 throw new Exception ("Cannot create the embedded server", e); 81 } 82 83 Runtime.getRuntime().addShutdownHook(new ShutdownHook(embedded)); 85 86 embedded.start(); 88 89 } 90 91 95 static class ShutdownHook extends Thread { 96 97 100 private Embedded embedded = null; 101 102 106 public ShutdownHook(final Embedded embedded) { 107 this.embedded = embedded; 108 } 109 110 113 @Override 114 public void run() { 115 try { 117 embedded.stop(); 118 } catch (EmbeddedException e) { 119 System.err.println("Error while stopping embedded server"); 120 e.printStackTrace(System.err); 121 } 122 } 123 } 124 } 125 | Popular Tags |