Sometimes, for example during debugging, it is useful to check if your code is running from the Eclipse IDE to exclude certain code from execution.
How can this be done? Here is an example:
public class mainClass {
public static void main(String[] args) {
String inEclipse = System.getProperty("ineclipse");
if ((inEclipse == null) || (!inEclipse.equals("true"))) {
System.out.println("Not running from Eclipse");
System.out.println(inEclipse);
} else {
System.out.println("Running from Eclipse");
System.out.println(inEclipse);
}
}
}
The other thing we need to do here is to set the VM argument “ineclipse” in the “Run Configurations”:
Here is the output from the example from within Eclipse and from the command line: