Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Java to indicate if code is running from IntelliJ/Eclipse etc or command line

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

like image 518
Nir Avatar asked Mar 11 '13 12:03

Nir


People also ask

How do I know if a Program is running in Eclipse?

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

What is the Run command in IntelliJ?

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.

How do I get command line arguments in IntelliJ?

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.

Is IntelliJ and Eclipse the same?

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.


1 Answers

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.

like image 103
BullyWiiPlaza Avatar answered Oct 20 '22 01:10

BullyWiiPlaza