I can launch my app as standalone app (for example from command line) or one specific way -- it is directly "from" source code, i.e. using IntelliJ.
Is there a way to detect if app was launched from IntelliJ or not? Only this, binary decision.
Workarounds are plenty, adding extra option when launching, however I am looking for direct solution, like this for C# How to know that the application is launched by debugger (VisualStudio) C#
The solution can be valid for any IDE, but must be valid at least for IntelliJ.
For those (including me) seeking ready to use code (Scala code):
object ProgramInfo
{
val isStandaloneApp = sun.management.ManagementFactory.getRuntimeMXBean().getInputArguments.isEmpty
val isDebugMode = scala.collection.JavaConversions.iterableAsScalaIterable(sun.management.ManagementFactory.getRuntimeMXBean().getInputArguments).exists(it => it.startsWith("-agentlib"))
}
It won't work in complex cases, but if you don't pass ton of parameters to JVM, it's just fine.
Run the program in debug modeClick the Run icon in the gutter, then select Modify Run Configuration. Enter arguments in the Program arguments field. Click the Run button near the main method. From the menu, select Debug.
I have used the below in the past to check the debug settings. You could use something similar
ManagementFactory.getRuntimeMXBean().getInputArguments()
When I run an application in IDEA, it sets some variable like -Didea.launcher.port, and -Didea.launcher.bin.path. Maybe you could check if they are set or not.
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