throw new JellyException("Script file " + scriptFile + " not found");
}
try {
// extract the -o option for the output file to use
final XMLOutput output = cmdLine.hasOption("o") ?
XMLOutput.createXMLOutput(new FileWriter(cmdLine.getOptionValue("o"))) :
XMLOutput.createXMLOutput(System.out);
Jelly jelly = new Jelly();
jelly.setScript(scriptFile);
final Script script = jelly.compileScript();
// add the system properties and the command line arguments
final JellyContext context = jelly.getJellyContext();
context.setVariable("args", args);
context.setVariable("commandLine", cmdLine);
if (runInSwingThread) {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() {
try {
script.run(context, output);
} catch (Exception ex) {
ex.printStackTrace();
}
} } ); } else {
script.run(context, output);
}
// now lets wait for all threads to close
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
try {
output.close();
}
catch (Exception e) {
// ignore errors
}
}