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.