1 17 18 package org.apache.geronimo.deployment.mavenplugin; 19 20 import java.io.File ; 21 import java.io.ObjectInputStream ; 22 import java.net.URI ; 23 import java.net.URL ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.StringTokenizer ; 28 import javax.management.ObjectName ; 29 import javax.management.MalformedObjectNameException ; 30 31 import org.apache.geronimo.gbean.GBeanData; 32 import org.apache.geronimo.kernel.KernelFactory; 33 import org.apache.geronimo.kernel.Kernel; 34 import org.apache.geronimo.kernel.config.ConfigurationManager; 35 import org.apache.geronimo.kernel.config.ConfigurationUtil; 36 import org.apache.geronimo.kernel.config.Configuration; 37 import org.apache.geronimo.kernel.config.InvalidConfigException; 38 import org.apache.geronimo.kernel.log.GeronimoLogging; 39 import org.apache.geronimo.system.url.GeronimoURLFactory; 40 41 47 public class StartServer { 48 49 static { 50 GeronimoLogging.initialize(GeronimoLogging.INFO); 52 53 GeronimoURLFactory.install(); 55 } 56 57 private String geronimoHome; 58 private String kernelName; 59 private String domainName; 60 private String configs; 61 62 public String getGeronimoHome() { 63 return geronimoHome; 64 } 65 66 public void setGeronimoHome(String geronimoHome) { 67 this.geronimoHome = geronimoHome; 68 } 69 70 public String getKernelName() { 71 return kernelName; 72 } 73 74 public void setKernelName(String kernelName) { 75 this.kernelName = kernelName; 76 } 77 78 public String getDomainName() { 79 return domainName; 80 } 81 82 public void setDomainName(String domainName) { 83 this.domainName = domainName; 84 } 85 86 public String getConfigs() { 87 return configs; 88 } 89 90 public void setConfigs(String configs) { 91 this.configs = configs; 92 } 93 94 public void execute() throws Exception { 95 System.setProperty("geronimo.base.dir", getGeronimoHome()); 96 List configList = new ArrayList (); 97 for (StringTokenizer st = new StringTokenizer (configs); st.hasMoreTokens();) { 98 configList.add(new URI (st.nextToken())); 99 } 100 File root = new File (getGeronimoHome()); 101 URL systemURL = new File (root, "bin/server.jar").toURL(); 102 URL configURL = new URL ("jar:" + systemURL.toString() + "!/META-INF/config.ser"); 103 GBeanData configuration = new GBeanData(); 104 ObjectInputStream ois = new ObjectInputStream (configURL.openStream()); 105 try { 106 configuration.readExternal(ois); 107 } finally { 108 ois.close(); 109 } 110 URI configurationId = (URI ) configuration.getAttribute("id"); 111 ObjectName configName = Configuration.getConfigurationObjectName(configurationId); 112 configuration.setName(configName); 113 114 Kernel kernel = KernelFactory.newInstance().createKernel(getKernelName()); 116 kernel.boot(); 117 118 kernel.loadGBean(configuration, this.getClass().getClassLoader()); 119 kernel.setAttribute(configName, "baseURL", systemURL); 120 kernel.startRecursiveGBean(configName); 121 122 ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel); 124 for (Iterator i = configList.iterator(); i.hasNext();) { 125 URI configID = (URI ) i.next(); 126 List list = configurationManager.loadRecursive(configID); 127 for (Iterator iterator = list.iterator(); iterator.hasNext();) { 128 ObjectName name = (ObjectName ) iterator.next(); 129 kernel.startRecursiveGBean(name); 130 System.out.println("started gbean: " + name); 131 } 132 } 133 134 135 } 136 } 137 | Popular Tags |