Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Maven Build and Test with One Button

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?

like image 506
Marvo Avatar asked Apr 22 '12 23:04

Marvo


People also ask

How do I run a single test file in Maven?

Execute a Single Test Class The Maven surefire plugin provides a test parameter that we can use to specify test classes or methods we want to execute. If we want to execute a single test class, we can execute the command mvn test -Dtest=”TestClassName”.

How do you build only test cases in Maven?

If you want to run just a single test instead of all the tests declared in your project, create a Maven run configuration for a single test with the Maven -Dtest=TestName test command.

How do I run a Maven build in Eclipse?

Building and Running the Maven Project in Eclipse To run the maven project, select it and go to “Run As > Java Application”. In the next window, select the main class to execute. In this case, select the App class and click on the Ok button. You will see the “Hello World” output in the Console window.

What is the difference between Eclipse build and Maven build?

Eclipse internal build (Eclipse's Build Project or Build All or Clean) and Maven/Ant build basically do the same thing which means that they both will compile the source code file. Now an obvious difference is that Eclipse internal build will not generate EAR, WAR etc. files for you, which you do using ANT/Maven.


2 Answers

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:

  1. Open preferences
  2. Open General->Keys
  3. Search for "maven test" (or "run maven test")
  4. Select the Run Maven Test entry
  5. Click on the field labeled Binding
  6. Press F7 (or whatever keystroke you want to bind)
  7. 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.

like image 104
Marvo Avatar answered Nov 17 '22 05:11

Marvo


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
like image 5
nwinkler Avatar answered Nov 17 '22 04:11

nwinkler