Дополнительные параметры в конфиге ServerWrapper.cfg

This commit is contained in:
Gravit 2018-09-24 18:55:39 +07:00
parent b1cddec0e4
commit e80551e108
2 changed files with 21 additions and 3 deletions

View file

@ -17,6 +17,7 @@
import ru.gravit.launcher.serialize.config.TextConfigReader; import ru.gravit.launcher.serialize.config.TextConfigReader;
import ru.gravit.launcher.serialize.config.TextConfigWriter; import ru.gravit.launcher.serialize.config.TextConfigWriter;
import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry;
import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry;
import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.launcher.serialize.config.entry.StringConfigEntry;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
@ -52,8 +53,15 @@ public static void main(String[] args) throws Throwable {
} }
} }
modulesManager.initModules(); modulesManager.initModules();
String classname = args[0]; String classname = config.mainclass.isEmpty() ? args[0] : config.mainclass;
Class<?> mainClass = Class.forName(classname); Class<?> mainClass;
if(config.customClassLoader) {
Class<ClassLoader> classloader_class = (Class<ClassLoader>) Class.forName(config.classloader);
ClassLoader loader = classloader_class.getConstructor(ClassLoader.class).newInstance(ClassLoader.getSystemClassLoader());
Thread.currentThread().setContextClassLoader(loader);
mainClass = Class.forName(classname,false,loader);
}
else mainClass = Class.forName(classname);
MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
String[] real_args = new String[args.length - 1]; String[] real_args = new String[args.length - 1];
System.arraycopy(args, 1, real_args, 0, args.length - 1); System.arraycopy(args, 1, real_args, 0, args.length - 1);
@ -81,9 +89,16 @@ private static void generateConfigIfNotExists() throws IOException {
} }
public static final class Config extends ConfigObject { public static final class Config extends ConfigObject {
public String title; public String title;
public boolean customClassLoader;
public String classloader;
public String mainclass;
protected Config(BlockConfigEntry block) { protected Config(BlockConfigEntry block) {
super(block); super(block);
title = block.getEntryValue("title",StringConfigEntry.class); title = block.getEntryValue("title",StringConfigEntry.class);
customClassLoader = block.getEntryValue("customClassLoader", BooleanConfigEntry.class);
if(customClassLoader)
classloader = block.getEntryValue("classloader",StringConfigEntry.class);
mainclass = block.getEntryValue("MainClass",StringConfigEntry.class);
} }
} }

View file

@ -1 +1,4 @@
title: "x"; title: "";
customClassLoader: false;
classloader: "ru.gravit.utils.PublicURLClassLoader";
MainClass: "";