1 11 12 package org.jivesoftware.messenger.starter; 13 14 import org.jivesoftware.util.Log; 15 16 import java.io.File ; 17 18 38 public class ServerStarter { 39 40 43 private static final String DEFAULT_LIB_DIR = "../lib"; 44 45 public static void main(String [] args) { 46 new ServerStarter().start(); 47 } 48 49 54 private void start() { 55 try { 57 final ClassLoader parent = findParentClassLoader(); 59 60 String libDirString = System.getProperty("messenger.lib.dir"); 61 62 File libDir; 63 if (libDirString != null) { 64 libDir = new File (libDirString); 67 if (!libDir.exists()) { 68 Log.warn("Lib directory " + libDirString + 69 " does not exist. Using default " + DEFAULT_LIB_DIR); 70 libDir = new File (DEFAULT_LIB_DIR); 71 } 72 } 73 else { 74 libDir = new File (DEFAULT_LIB_DIR); 75 } 76 77 ClassLoader loader = new JiveClassLoader(parent, libDir); 78 79 Thread.currentThread().setContextClassLoader(loader); 80 Class containerClass = loader.loadClass( 81 "org.jivesoftware.messenger.XMPPServer"); 82 containerClass.newInstance(); 83 } 84 catch (Exception e) { 85 e.printStackTrace(); 86 } 87 } 88 89 94 private ClassLoader findParentClassLoader() { 95 ClassLoader parent = Thread.currentThread().getContextClassLoader(); 96 if (parent == null) { 97 parent = this.getClass().getClassLoader(); 98 if (parent == null) { 99 parent = ClassLoader.getSystemClassLoader(); 100 } 101 } 102 return parent; 103 } 104 } | Popular Tags |