java检查是否从命令行或资源管理器启动了jar [英] java check if jar was launched from command line or explorer

查看:155
本文介绍了java检查是否从命令行或资源管理器启动了jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检查jar是通过'java -jar test.jar'从命令行启动还是通过在资源管理器中双击?
我希望它从nogui模式开始,如果它是从命令提示符执行的。

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.

推荐答案

没有。无法确定它是如何发布的。您可以传递命令行参数,例如

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

然后解析 main中的参数()控制命令行或gui模式的方法。

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

这篇关于java检查是否从命令行或资源管理器启动了jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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