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
?