How to set a run/debug configuration by code


How to set a run/debug configuration by java code? 

I want to start another debug session where the configuration can not be determined from start

And when the fisrt application runs to somecode, I want to start the second application and debug it

so any way to set the configuration and run/debug it from code?

I just know how to run/debug a configuration from code lile below

RunManager instance = RunManager.getInstance(project);
RunnerAndConfigurationSettings runnerAndConfigurationSettings = instance.getSelectedConfiguration();
ProgramRunnerUtil.executeConfiguration(runnerAndConfigurationSettings, DefaultDebugExecutor.getDebugExecutorInstance());

but I have no idea about how to create a RunnerAndConfigurationSettings object by code

I saw there are some methods of RunManager that seems to  be able to create. However I can not figure out how to use them.

1 comment

RunManager#createConfiguration is correct approach. You need to determine ConfigurationFactory depending on run configuration type (e.g., Java application/Server/...) and then accordingly fill required parameters. see org.jetbrains.idea.devkit.gradle.GradleIntellijPluginFrameworkSupportProvider#createRunConfiguration for sample



Please sign in to leave a comment.