}
log.info("Starting Geronimo server...");
// Setup the JVM to start the server with
final Java java = (Java)createTask("java");
java.setJar(new File(geronimoHome, "bin/server.jar"));
java.setDir(geronimoHome);
java.setFailonerror(true);
java.setFork(true);
if (javaVirtualMachine != null) {
if (!javaVirtualMachine.exists()) {
throw new MojoExecutionException("Java virtual machine is not valid: " + javaVirtualMachine);
}
log.info("Using Java virtual machine: " + javaVirtualMachine);
java.setJvm(javaVirtualMachine.getCanonicalPath());
}
if (timeout > 0) {
java.setTimeout(new Long(timeout * 1000));
}
if (maximumMemory != null) {
java.setMaxmemory(maximumMemory);
}
// Load the Java programming language agent for JPA
File javaAgentJar = new File(geronimoHome, "bin/jpa.jar");
if (javaAgentJar.exists()) {
java.createJvmarg().setValue("-javaagent:" + javaAgentJar.getCanonicalPath());
}
// Propagate some properties from Maven to the server if enabled
if (propagateGeronimoProperties) {
Properties props = System.getProperties();
Iterator iter = props.keySet().iterator();
while (iter.hasNext()) {
String name = (String)iter.next();
String value = System.getProperty(name);
if (name.equals("geronimo.bootstrap.logging.enabled")) {
// Skip this property, never propagate it
}
else if (name.startsWith("org.apache.geronimo") || name.startsWith("geronimo")) {
if (log.isDebugEnabled()) {
log.debug("Propagating: " + name + "=" + value);
}
setSystemProperty(java, name, value);
}
}
}
// Apply option sets
if (options != null && (optionSets == null || optionSets.length == 0)) {
throw new MojoExecutionException("At least one optionSet must be defined to select one using options");
}
else if (options == null) {
options = "default";
}
if (optionSets != null && optionSets.length != 0) {
OptionSet[] sets = selectOptionSets();
for (int i=0; i < sets.length; i++) {
if (log.isDebugEnabled()) {
log.debug("Selected option set: " + sets[i]);
}
else {
log.info("Selected option set: " + sets[i].getId());
}
String[] options = sets[i].getOptions();
if (options != null) {
for (int j=0; j < options.length; j++) {
java.createJvmarg().setValue(options[j]);
}
}
Properties props = sets[i].getProperties();
if (props != null) {
Iterator iter = props.keySet().iterator();
while (iter.hasNext()) {
String name = (String)iter.next();
String value = props.getProperty(name);
setSystemProperty(java, name, value);
}
}
}
}
// Set the properties which we pass to the JVM from the startup script
setSystemProperty(java, "org.apache.geronimo.base.dir", geronimoHome);
// Use relative path
setSystemProperty(java, "java.io.tmpdir", "var/temp");
setSystemProperty(java, "java.endorsed.dirs", prefixSystemPath("java.endorsed.dirs", new File(geronimoHome, "lib/endorsed")));
setSystemProperty(java, "java.ext.dirs", prefixSystemPath("java.ext.dirs", new File(geronimoHome, "lib/ext")));
if (quiet) {
java.createArg().setValue("--quiet");
}
else {
java.createArg().setValue("--long");
}
if (verbose) {
java.createArg().setValue("--verbose");
}
if (veryverbose) {
java.createArg().setValue("--veryverbose");
}
if (startModules != null) {
if (startModules.length == 0) {
throw new MojoExecutionException("At least one module name must be configured with startModule");
}
log.info("Overriding the set of modules to be started");
java.createArg().setValue("--override");
for (int i=0; i < startModules.length; i++) {
java.createArg().setValue(startModules[i]);
}
}
//
// TODO: Check if this really does capture STDERR or not!
//
if (logOutput) {
File file = getLogFile();
FileUtils.forceMkdir(file.getParentFile());
log.info("Redirecting output to: " + file);
java.setOutput(file);
}
// Holds any exception that was thrown during startup
final ObjectHolder errorHolder = new ObjectHolder();
StopWatch watch = new StopWatch();
watch.start();
// Start the server int a seperate thread
Thread t = new Thread("Geronimo Server Runner") {
public void run() {
try {
java.execute();
}
catch (Exception e) {
errorHolder.set(e);
//