如何重启java应用程序,记住它的命令行参数 [英] how to restart java application, remembering its command line arguments
本文介绍了如何重启java应用程序,记住它的命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个java应用程序。它可以通过几个命令行标志启动。我想提供用户重启应用程序的能力。
I have a java application. It can be started with couple of command line flags. I want to provide ability "restart" the application by user.
目前我们将参数保存在控制文件中,在重新启动应用程序时读取它。重启应用程序的最佳方法是什么 - 如何保留命令行参数?
Currently we save the the arguments on a control file, reads it when restarting the application. What is the best way to restart the application - how can I retain the command line arguments?
推荐答案
使用您可以检索的RuntimeMXBean,Classpath,Bootclasspath等。
Using the RuntimeMXBean you could retrieve , Classpath, Bootclasspath etc.
package com;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
class JMXTest {
public static void main(String args[]) {
try {
for ( int i = 0 ; i < args.length ; i++ )
System.out.println( "args :" + args[i] );
RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean();
System.out.println( "boot CP:" + mx.getBootClassPath() );
System.out.println( " CP:" + mx.getClassPath() );
System.out.println( "cmd args:" + mx.getInputArguments() );
}
catch( Exception e ) {
e.printStackTrace();
}
}
}
这篇关于如何重启java应用程序,记住它的命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文