Is there a way to know if a Java program was start

2020-05-21 08:16发布

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:

if( !file.exists() ) {
    if( fromCommandLine()){
        System.out.println("File doesn't exists");
    }else if ( fromDoubleClickOnJar() ) {
        JOptionPane.showMessage(null, "File doesn't exists");
    }
 }

7条回答
时光不老,我们不散
2楼-- · 2020-05-21 09:04

You can get all the input arguments with RuntimeMBean.getInputArguments(), this can be used to detect when debugging is enabled.

EDIT: However, the -jar argument isn't one of them. :(

查看更多
登录 后发表回答