![JAR search and dependency download from the Maven repository](/logo.png)
de.tsl2.nano.execution.Runner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tsl2.nano.common Show documentation
Show all versions of tsl2.nano.common Show documentation
TSL2 Framework Commons (Collections, Actions/Excecution, Readers, Xml, Print, Mail, FuzzyFinder, Proxies, Network-Structure)
The newest version!
/*
* File: $HeadURL$
* Id : $Id$
*
* created by: Thomas Schneider
* created on: Feb 27, 2012
*
* Copyright: (c) Thomas Schneider 2012, all rights reserved
*/
package de.tsl2.nano.execution;
import java.io.File;
import java.io.FileReader;
import java.lang.reflect.Method;
import java.util.Properties;
import de.tsl2.nano.core.cls.BeanClass;
import de.tsl2.nano.core.execution.ICRunnable;
/**
* Simple java main runner for {@link ICRunnable} implementations. Uses a {@link Properties} from file-load as arguments.
*
* @author Thomas Schneider
* @version $Revision$
*/
public class Runner {
public static final void main(String[] args) throws Exception {
if (args.length < 1) {
System.out.println("Please give at least the ICRunnable to start!");
return;
} else if (args.length < 2) {
System.out.println("Please give a property-file name as second parameter!");
return;
}
final Properties p = new Properties();
p.load(new FileReader(new File(args[1])));
for (int i = 0; i < args.length; i++) {
p.setProperty("args" + i, args[i]);
}
final Class> rclass = (Class>) BeanClass.load(args[0]);
final Method runMethod = rclass.getMethod("run", new Class[] { Object.class, Object[].class });
log("starting " + runMethod + " with arguments: " + p);
final Object result = runMethod.invoke(null, new Object[] { p });
log("finished " + runMethod + " with result: " + result);
}
protected static void log(String text) {
System.out.println(text);
}
public static Class[] methodArgs(Object[] args) {
final Class[] margs = new Class[args.length];
for (int i = 0; i < args.length; i++) {
margs[i] = args[i].getClass();
}
return margs;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy