How can I write the code which can behavior differently in run time under “debug” mode (e.g. invoked as “Debug As Java Application” in eclipse) from under “run” mode (e.g. invoked as “Run As Java Application” in eclipse”)? That is, for example, the code can print “Haha, you are in debug” when “Debug As Java Application” but print nothing when “Run As Java Application” (I don’t want to append any args when invoking main method). Is there any general method to implement this which can work under any IDEs, like eclipse, IntelliJ etc?
Share
I have implemented this as following. I examine the JVM parameters and look for one that is
-Xdebug. Please see the code.It works for me because eclipse executes application that is being debugged as separate process and connects to it using JDI (Java Debugging Interface).
I’d be happy to know whether this works with other IDEs (e.g. IntelliJ)