The most common build activity I do in Eclipse (other than allowing auto-build to do its thing) is to perform a "Maven Build..." with parameters of clean and package. This runs all my tests. m2eclipse does a great job with this, and I like the output. If a test breaks, I then jump to using the JUnit plug-in, the debugger, etc.
I've used "Organize favorites..." under the Run (and Debug) button's drop down menu to make this kind of build "permanent" and somewhat easy to access and use.
But not easy enough.
What I have now is a button that morphs from moment to moment, based on my last activity, what file I have open, or what item I have selected in the project window. Yes, I can click the down-arrow next to the run button, select the favorite for "clean-and-package" but for something that I do hundreds of times a day, that's too difficult.
I want ONE BUTTON. A big ol' button on the tool bar that I just click and boom goes the dynamite. I'll also accept a way of assigning a hot key to my build favorite so I can press, say, ctrl+r or something to run my favorite item.
What'cha got for me?
I've rediscovered key bindings in Eclipse. It's not exactly what I want, but it works well enough, I suppose. I simply bind F7 to Maven's test hook. It's not the same as "mvn clean package
" but it'll do until I find a better solution.
Here's how I did it:
- Open preferences
- Open General->Keys
- Search for "maven test" (or "run maven test")
- Select the Run Maven Test entry
- Click on the field labeled Binding
- Press F7 (or whatever keystroke you want to bind)
- Probably best to set the When field to in Windows
Now, when you press F7, eclipse will run "mvn test
".
For whatever reason, and I'm sure it's a perfectly good one, the m2eclipse plugin authors didn't provide a "Run Maven package" hook. Sigh.
It looks like there's a couple of ways to do this - none directly in Eclipse:
- Create your own small plugin that defines the key binding, see here: eclipse: put keyboard shortcuts on specific launch configurations
- Use Practically Macro - also see here: Assigning a keyboard shortcut for a specific Eclipse build configuration
- Use some form of scripting, e.g. this: http://mackaz.de/72
If you create a Maven Run Configuration and put a number as the first character in the name, then you can use Shift-Alt-X Ctrl-M N, where N is the number you gave as first character in the name. For your case, do the following.
- Right click on your project, select Run As and then select Maven
build... This will open a dialog to create a new Maven Run
Configuration.
- Make the name of the configuration 1 - test.
- Put test as the goal.
- Press Apply and then Close.
- Type Shift-Alt-X Ctrl-M 1. This will select the configuration you just created.
- Press enter will launch it.