Inceptum/wrapper/src/main/java/io/gitlab/jfronny/inceptum/WrapperStrap.java

29 lines
1.3 KiB
Java
Raw Normal View History

package io.gitlab.jfronny.inceptum;
import io.gitlab.jfronny.inceptum.util.Utils;
2022-01-20 00:03:46 +01:00
import java.io.File;
2022-01-19 23:44:06 +01:00
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
2022-01-19 23:44:06 +01:00
import java.net.URISyntaxException;
import java.nio.file.Path;
public class WrapperStrap {
2022-01-19 23:44:06 +01:00
public static final ClassLoader SYSTEM_LOADER = ClassLoader.getSystemClassLoader();
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException, URISyntaxException, NoSuchFieldException {
Utils.LOGGER.info("Starting Inceptum Wrapper ClassLoader");
2022-01-20 00:03:46 +01:00
switchEnv(new File(WrapperStrap.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toPath(),
"io.gitlab.jfronny.inceptum.Wrapper",
args);
}
2022-01-19 23:44:06 +01:00
public static void switchEnv(Path jar, String mainClass, String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException, URISyntaxException, NoSuchFieldException {
ClassLoader loader = new WrapperClassLoader(jar);
Thread.currentThread().setContextClassLoader(loader);
loader.loadClass(mainClass)
.getDeclaredMethod("main", String[].class)
.invoke(null, new Object[] {args});
}
}