java check if jar was launched from command line o

2019-01-28 13:31发布

This question already has an answer here:

Is there a way to check if the jar was launched from command line via 'java -jar test.jar' or via double click in explorer? I want it to start in nogui mode if it was executed from the command prompt.

1条回答
Viruses.
2楼-- · 2019-01-28 13:51

No. There is no way to determine how it was launched. You could pass a command line argument like

java -cp . my.package.Example -nogui

And then parse the argument in your main() method to control the "command line" or "gui" mode.

查看更多
登录 后发表回答