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
You can do that by opening the "Open Run Dialog" ("Run" menu), then select your type of application and add in the "Arguments" tab a -DrunInEclipse=true . In your Java code, you can check the value of the property: String inEclipseStr = System. getProperty("runInEclipse"); boolean inEclipse = "true".
Run applications Last modified: 28 July 2022. Run a class with a main() method: Shift+F10. You can run applications right from IntelliJ IDEA if you have an SDK set up for your project/module.
From the main menu, select Run | Edit Configurations or choose Edit Configurations from the run/debug configurations selector on the toolbar. In the Run/Debug Configurations dialog that opens, select a configuration where you want to pass the arguments. Type the arguments in the Program arguments field.
IntelliJ and Eclipse are both Java development environments, and both IDEs have a lot of features in common. They are both very good at code completion, refactoring, and debugging. The critical difference between the two is that IntelliJ is more customizable and has better support for Maven and Gradle builds.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With