I implemented this as the following. I am studying the JVM options and looking at -Xdebug. See Code.
private final static Pattern debugPattern = Pattern.compile("-Xdebug|jdwp");
public static boolean isDebugging() {
for (String arg : ManagementFactory.getRuntimeMXBean().getInputArguments()) {
if (debugPattern.matcher(arg).find()) {
return true;
}
}
return false;
}
It works for me because eclipse runs an application that is debugged as a separate process and connects to it using JDI (Java debugging interface).
I would be happy to know if this works with other IDEs (e.g. IntelliJ)
source
share