If you’ve used Eclipse for a while, you may have run into the commands Run As and Debug As. These are used to launch a class/project as a particular application, eg. a Java application, JUnit test or Eclipse application.
They’re normally accessed with the mouse via the right-click menu or the pulldown menu on the run/debug icons in the toolbar. However, using the mouse to launch these classes isn’t the fastest way of doing things, especially if you’re frequently running different classes, such as JUnit tests.
To help with this, Eclipse has keyboard shortcuts to invoke the Run As/Debug As commands. They really speed up launching apps (which you’ll do often in a day’s work). I’ll show you these shortcuts and also a couple of others to make life easier.
How to Run As/Debug As with the keyboard
Here are the keyboard shortcuts for a couple of the more popular launchers. You can, of course, configure any of these keys to make them easier by going to Window > Preference > General > Keys, especially if it’s a launcher you use often.
|Alt+Shift+X, J||Alt+Shift+D, J||Run/debug as a Java application. Produces an error message if the class doesn’t contain a static main method.|
|Alt+Shift+X, T||Alt+Shift+D, T||Run/debug as a JUnit test. Produces an error message if the class doesn’t extend TestCase or doesn’t include JUnit 4 @Test annotations.|
|Alt+Shift+X, Q||Alt+Shift+D, Q||Run/debug as an Ant build. Produces an error message if the file isn’t valid Ant XML.|
|Alt+Shift+X, E||Alt+Shift+D, E||Run/debug as an Eclipse application. This spawns another Eclipse instance and deploys your development plugins to that instance so you can test your plugins. Runs an Eclipse RCP application if you have one defined.|
|Alt+Shift+X, P||Alt+Shift+D, P||Run/debug as an Eclipse JUnit Plugin test. Same as JUnit, but runs the test under the OSGi framework as a bundle. Used to test Eclipse applications and plugins.|
The list is not exhaustive as I’ve only listed the more popular ones and you may have plugins that contribute more launchers. You can get a full list of the available ones by pressing and releasing Alt+Shift+X. After a second, a popup will appear in the bottom right corner with the list of available options. Here’s an example of what you might see:
Alternatively go to Windows > Preferences > General > Keys and search for “Run” – you’ll get a more comprehensive list, even for ones without existing key bindings.
Eclipse is also nice enough to show you the shortcuts on the menu items, just in case you forget them.
Relaunching the last launched application
So now that you know how to launch the class initially, you may want to rerun this class a couple of times before you’re done. Using a shortcut is much faster than reaching for the mouse to click the toolbar icon, so here are the shortcuts to use:
|F11||Launch the last launched application in debug mode (ie. allow breakpoints, hotswapping of code, etc).|
|Ctrl+F11||Launch the last launched application, but not in debug mode. Breakpoints will be skipped and there’ll be no Hotswapping.|
|Ctrl+Shift+F11||Launch the last launched external tool, eg. a command line app, external Ant file, etc. Only useful if you have configured external tools via Run > External Tools or some other way.|
- Skip over certain classes when using Step Into in Eclipse’s debugger
- Always run/debug the last launched class instead of the selected one in Eclipse