Can I find out if the java program was launched using java or javaw

后端 未结 3 1669
半阙折子戏
半阙折子戏 2020-12-10 15:51

This is related to an earlier question by a different user, asking How to detect that code is running inside eclipse IDE.

I noticed that Eclipse always launches prog

3条回答
  •  既然无缘
    2020-12-10 16:35

    Checking for System.console() didn't work for me, because of:

    1. It requires JDK 6 or later
    2. Console object is also missing, if application was run through the Runtime.exec(String) method. This was critical for me, because we using a lot of automated script.

    So I'm using following solution:

    private static boolean isJavaw() {
      try {
        System.in.available();
        return false;
      } catch (IOException e) {
        // invalid handle in case of javaw
        return true;
      }
    }
    

    Works fine with JDKs 5, 6 and 7.

提交回复
热议问题