Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning a keyboard shortcut for a specific Eclipse build configuration

Tags:

In our Java project in Eclipse, we have several build configurations, as we have an engine that when run, builds installation jar for a specific projects according to the parameters it gets, so each build configuration run the same build with different parameters to build installation for a specific project.

Currently, I have to go to the Run Configuration drop-down button in the toolbar to start the engine, and I need to select the build configuration from the list in order to run (or debug) the engine with the required parameters.

I have configured Eclipse to run the last run execution if the button is run instead of selecting from the drop-down menu, but I would really like to have separate buttons in the toolbar for each build configuration (or for my favorite configurations), and even better, have a keyboard shortcut to run (or debug) a specific build configuration. Is that possible?

like image 502
splintor Avatar asked Sep 17 '09 07:09

splintor


2 Answers

I was able to put together specific steps based on splintor's thread and get this working (I also added a loop at the top that finds any existing launch with the same name and terminates it, effectively making this a "restart" macro):

To assign keyboard shortcuts to specific Eclipse launch configurations, perform the following steps:

  • Install https://sourceforge.net/projects/practicalmacro/, which you can inside Eclipse via Help->Software Updates: http://puremvcnotificationviewer.googlecode.com/svn/trunk/PracticallyMacroGoogleUpdateSite

  • Restart Eclipse and open Eclipse Preferences. You will have a new section called "Practically Macro Options", expand that section.

  • Click on "Editor Macro Definitions"

  • Click on "new..."

  • In the list of available commands, scroll down to "Editor Macro script (Beanshell)", select it and then click "Add->"

  • When the script editor pops up, add the following code to the existing code:

    import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.ui.DebugUITools;     try     {       // Terminate process if it already exists from a previous launch        org.eclipse.debug.core.ILaunch[] allLaunches=DebugPlugin.getDefault().getLaunchManager().getLaunches();       for (ILaunch l : allLaunches)       {                       if (l.getLaunchConfiguration().getName().equals("YOUR CONFIG NAME HERE"))         {           console.write("terminating launch: " );           console.writeln(l.getLaunchConfiguration().getName());           l.terminate();           break;          }       }          org.eclipse.debug.core.ILaunchConfiguration[] allConfigurations=DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations();         for (ILaunchConfiguration config : allConfigurations) {             if (config.getName().equals("YOUR CONFIG NAME HERE"))             {                 DebugUITools.launch(config, "debug");                 break;             }         }     } catch (CoreException e) {         e.printStackTrace();     }     finally{} 
  • Note line 11 that checks the configuration name, replace with whatever you want

  • Also note DebugUITools.launch command on line 15, you can pass either "run" or "debug"

  • In the "Macro info" section at the bottom of this dialog, specify a macro name

  • IMPORTANT!: If you want to be able to see this macro in the standard Eclipse key binding dialog, you need to assign an id. I started with 1...

  • Click OK

  • Expand the "General" section and click on "Keys"

  • You can now search the possible key bindings for your new macro's name and assign it to any key you want.

  • NOTE: After assigning a key I often had to close and restart Eclipse before the key binding was respected.

like image 92
Jeremy Mullin Avatar answered Sep 19 '22 16:09

Jeremy Mullin


I was able to do it using Practically Macro - see this thread.

like image 35
splintor Avatar answered Sep 17 '22 16:09

splintor