I would like to know if there is an option to write programmatic if code is running via Eclipse/IntelliJ or any other editor or running from command line
I was thinking to use System.getProperty() but is there any property that indicate it?
Thanks in advance
Nir
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.
The following code can detect whether your code is ran from
IntelliJ IDEA
or not.It's tested working on
Linux
,Mac OS X
andWindows
so it should be platform independent.