All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.dbstarll.utils.lang.launcher.MainLauncher Maven / Gradle / Ivy

The newest version!
package io.github.dbstarll.utils.lang.launcher;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public abstract class MainLauncher extends AbstractLauncher {
    @Override
    protected final int run(Class taskClass, String... args) throws LaunchException, Throwable {
        Method method;
        try {
            method = taskClass.getMethod("main", new Class[]{String[].class});
        } catch (Throwable ex) {
            throw new LaunchException(ex);
        }

        try {
            method.invoke(null, new Object[]{args});
        } catch (InvocationTargetException ex) {
            throw ex.getTargetException();
        } catch (Throwable ex) {
            throw new LaunchException(ex);
        }
        return 0;
    }
}