]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/AppLauncher.java
Introduce SLC Detached app launcher
[gpl/argeo-slc.git] / org.argeo.slc.detached / src / main / java / org / argeo / slc / detached / AppLauncher.java
1 package org.argeo.slc.detached;
2
3 import java.lang.reflect.Method;
4 import java.util.List;
5 import java.util.Properties;
6 import java.util.Vector;
7
8 public class AppLauncher {
9 private Properties systemProperties = new Properties();
10 private String mainClass = null;
11 private List arguments = new Vector();
12
13 public void launch() {
14 try {
15 if (mainClass == null)
16 throw new DetachedException(
17 "A main class name muste be specified.");
18
19 System.getProperties().putAll(systemProperties);
20 //Class clss = getClass().getClassLoader().loadClass(mainClass);
21 Class clss = Class.forName(mainClass);
22
23 String[] args = new String[arguments.size()];
24 for (int i = 0; i < arguments.size(); i++) {
25 args[i] = arguments.get(i).toString();
26 }
27
28 Class[] mainArgsClasses = new Class[] { args.getClass() };
29 Object[] mainArgs = { args };
30 Method mainMethod = clss.getMethod("main", mainArgsClasses);
31 mainMethod.invoke(null, mainArgs);
32
33 } catch (Exception e) {
34 throw new DetachedException("Unexpected exception while launching "
35 + mainClass, e);
36 }
37
38 }
39
40 public void setSystemProperties(Properties systemProperties) {
41 this.systemProperties = systemProperties;
42 }
43
44 public void setMainClass(String mainClass) {
45 this.mainClass = mainClass;
46 }
47
48 public void setArguments(List arguments) {
49 this.arguments = arguments;
50 }
51
52 }