javaintellij-ideacommand-lineconsoledevelopment-environment

Check if Java code is running from IntelliJ, Eclipse, etc or command line


I would like to know if there is a way (programmatically) to check if a code is running within Eclipse, IntelliJ, any other editor or running from the command line (console).

I was thinking to use System.getProperty() but is there any property that indicate this?


Solution

  • 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.