Inceptum/launchwrapper/src/main/java/io/gitlab/jfronny/inceptum/launchwrapper/Main.java

34 lines
1.3 KiB
Java

package io.gitlab.jfronny.inceptum.launchwrapper;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.*;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) throws ClassNotFoundException, IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
if (args.length == 0) throw new IllegalArgumentException("Missing class argument");
String forceloadNatives = System.getProperty("inceptum.forceloadNatives");
if (forceloadNatives != null) {
Path p = Paths.get(forceloadNatives);
if (Files.exists(p)) {
try (Stream<Path> paths = Files.list(p)) {
paths.forEach(Main::load);
}
} else {
throw new IllegalArgumentException("Could not find forceloadNatives path");
}
}
Class<?> mainClass = Class.forName(args[0]);
String[] newArgs = new String[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, args.length - 1);
mainClass.getMethod("main", String[].class).invoke(null, new Object[] {newArgs});
}
private static void load(Path path) {
System.load(path.toAbsolutePath().normalize().toString());
}
}