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

前端 未结 7 2113
伪装坚强ぢ
伪装坚强ぢ 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:09

    From http://java.itags.org/java-essentials/15972/

    try {
        GraphicsEnvironment.getLocalGraphicsEnvironment();
    } catch(Throwable ex) {
        System.out.println("No graphical environment is available.");
    }
    

提交回复
热议问题