cc.shacocloud.mirage.loader.Launcher Maven / Gradle / Ivy
package cc.shacocloud.mirage.loader;
import java.lang.reflect.Method;
/**
* Mirage 启动器的顶层类
*
* @author 思追(shaco)
* @date 2023/3/15
*/
public interface Launcher {
String START_CLASS_ATTRIBUTE = "Start-Class";
String CLASSES_ATTRIBUTE = "Mirage-Classes";
String LIB_INDEX_ATTRIBUTE = "Mirage-Lib-Index";
/**
* 启动方法
*
* @param args 启动参数
*/
default void run(String[] args) throws Exception {
// 创建类加载器
ClassLoader classLoader = createClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
// 执行主类
Class> mainClass = classLoader.loadClass(getMainClassName());
Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
mainMethod.setAccessible(true);
mainMethod.invoke(null, new Object[]{args});
}
/**
* 创建类加载器
*/
ClassLoader createClassLoader() throws Exception;
/**
* 获取运行的主类名称
*/
String getMainClassName() throws Exception;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy