Is there a way to know if a Java program was started from the command line or from a jar file?

前端 未结 7 2010
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 20:45

I want to either display a message in the console or a pop up, so in case a parameter is not specified, I want to know to which should I display

Something like:

相关标签:
7条回答
  • 2021-02-03 21:18

    You can try with:

    if (System.console() != null) {
        // Console attached to the JVM: command prompt output
        System.out.println("...");
    } else {
        // No console: use Swing
    }
    
    0 讨论(0)
提交回复
热议问题