Java-获取命令行参数,主要以外吗? [英] Java - get command line arguments, OUTSIDE of main?

查看:51
本文介绍了Java-获取命令行参数,主要以外吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java中是否有一种方法可以获取传递给 main 函数的程序外部的命令行参数?

Is there a way in java to get the command line arguments that were passed to a program outside of the main function?

我正在编写一些代码,该代码是我无法控制的较大应用程序的一部分,并且我想知道命令行参数是什么,而无需修改 main 函数。

I'm writing some code that's part of a larger application I don't control, and I'd like to know what the command line args were, without modifying the main function.

注意:我见过如何获取JVM参数,以及如何在main中获取参数,但是希望将其保存到应用程序的其他部分,而无需将它们保存在我无法控制的 main 函数中。

Note: I've seen how to get the JVM arguments, and how to get the arguments in main, but would like to get it in other parts of our app, without having them saved in the main function, which I don't control.

推荐答案

以这种方式启动jvm时: java -DmyArgument = myValue -jar your.jar 可以获取值 String myArg = System.getProperty( myArgument);

When starting the jvm this way: java -DmyArgument=myValue -jar your.jar you can get the value of myArgument everywhere in your java code with String myArg = System.getProperty("myArgument");

这篇关于Java-获取命令行参数,主要以外吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆