package io.gitlab.jfronny.inceptum; import io.gitlab.jfronny.inceptum.util.Utils; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.URISyntaxException; import java.nio.file.Path; public class WrapperStrap { 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"); switchEnv(new File(WrapperStrap.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toPath(), "io.gitlab.jfronny.inceptum.Wrapper", args); } 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}); } }