[英]Java ClassLoader VM Arguments
下面的代码尝试启动外部可执行JAR文件。
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
设置main方法接收的Object[] arguments
但是如何设置VM参数,例如-XstartOnFirstThread
呢?
要设置JVM参数,您必须启动JVM。 您当前的代码将在已经运行的JVM中运行main方法。
要启动JVM,使用ProcessBuilder
运行java
命令可能是最简单的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.