How to rerun programmatically the program

Hi, I want to programmatically rerun(There is a command for this also you can use ctrl-f5) Below is a picture of rhis button in idea

So how I can run this action by myself?


Hi Evgeniy,

You should use ExecutionManager.restartRunProfile() for that.

Default IJ implementation achieves that via RestartAction (the one from your screenshot).



Thank you, this helped me a lot :)


I did it and restarted the process sucessfully. But if I have two or more processes running, I cannot rerun all of them, it just reruns one of them
Here is my code

     ToolWindowManager manager = ToolWindowManager.getInstance(e.getProject());         ToolWindow window = manager.getToolWindow("Run");         if (window == null) {             return;         }         Content[] contents = window.getContentManager().getContents();         for (Content content : contents) {             final RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(e.getProject());             final Collection<RunnerAndConfigurationSettings> allConfigurations = runManager.getSortedConfigurations();             for (RunnerAndConfigurationSettings runConfiguration : allConfigurations) {                 if (content.getTabName().contains(runConfiguration.getName())) {                     String name = runConfiguration.getName();                     System.out.println(name);                     content.setDisplayName("!" + name);                     ExecutionManager.getInstance(e.getProject()).restartRunProfile(e.getProject(),                             DefaultRunExecutor.getRunExecutorInstance(),                             DefaultExecutionTarget.INSTANCE,                             runManager.findConfigurationByName(name),                             e.getData(RunContentManager.RUN_CONTENT_DESCRIPTOR));                 }             }         }




and then use them for restarting with ExecutionManager.getInstance(project).restartRunProfile()

Also you can invoke RunContentDescriptor.getRestarter().run()


I don't have method getAllDescriptors() in 12 version of IDEA ?:|

UPDATE: sorry, it was on RunContentManager, not in ContentManager, my fault


OK, code snipped has been updated, my fault too.


I used the way you suggested, but there is only one tab reruns from all tabs in Run wndow
Here is my new code

public void actionPerformed(final AnActionEvent e) {         Project project = e.getProject();         if (project == null) {             return;         }         ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow("Run");         if (window == null) {             return;         }         for (final Content content : window.getContentManager().getContents()) {             final RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(project);             final Collection<RunnerAndConfigurationSettings> allConfigurations = runManager.getSortedConfigurations();             for (RunnerAndConfigurationSettings runConfiguration : allConfigurations) {                 System.out.println(runConfiguration.getName());                 ExecutionManager executionManager = ExecutionManager.getInstance(project);                 RunContentDescriptor descriptor = content.getUserData(new Key<RunContentDescriptor>("Descriptor"));                 RunnerAndConfigurationSettings configurationByName = runManager.findConfigurationByName(runConfiguration.getName());                 if (configurationByName == null) {                     continue;                 }                 List<ExecutionTarget> targets = ExecutionTargetManager.getTargetsFor(project, configurationByName);                 for (ExecutionTarget target : targets) {                     executionManager.restartRunProfile(project,                             DefaultRunExecutor.getRunExecutorInstance(),                             target,                             configurationByName,                             descriptor);                 }                 turnOffCheckbox(content);             }         }     }


Now there is a bug and you cannot restart more than one running instance at the same time. It's going to be fixed in next 13 EAP. You can use this code snippet:

    ExecutionManager executionManager = ExecutionManager.getInstance(project);
    List<RunContentDescriptor> descriptors = executionManager.getContentManager().getAllDescriptors();
    for (RunContentDescriptor descriptor : descriptors) {


Please sign in to leave a comment.