0
下面的代码尝试启动外部可执行JAR文件。Java ClassLoader VM参数
final File file = new File("/path/to/executable.jar");
JarFile jarFile = null;
jarFile = new JarFile(file);
final Manifest manifest = jarFile.getManifest();
final URLClassLoader child = new URLClassLoader(new URL[] { file.toURI().toURL() }, Launcher.class.getClassLoader());
final Class<?> classToLoad = Class.forName("com.example.launcher.Launcher", true, child);
final Method method = classToLoad.getDeclaredMethod("main", String[].class);
final Object[] arguments = { new String[0] };
method.invoke(null, arguments);
jarfile.close();
参数的主要方法接收可以在Object[] arguments
设置但如何将一组VM参数,如-XstartOnFirstThread
?