In Java to indicate if code is running from IntelliJ/Eclipse etc or command line
The following code can detect whether your code is ran from IntelliJ IDEA
or not.
public static boolean runningFromIntelliJ()
{
String classPath = System.getProperty("java.class.path");
return classPath.contains("idea_rt.jar");
}
It's tested working on Linux
, Mac OS X
and Windows
so it should be platform independent.
There is no reliable way to do that. The IDE itself would use a JRE / JDK that is installed on your system or one that comes packaged with the IDE. There is nothing in the SDK / JVM that specifically identifies itself as running from within an IDE.
If you need to identify this in your program, pass a system property through the -D flag when you run the code from the IDE. The presence (or absence) of this property can be used to determine where the code is being run from.