Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Key binding in Eclipse for Maven package command

I want to bind the mvn package command in eclipse. So I used the normal procedure to do this: Window->Preferences->General->Keys and then I filtered for Maven. The only commands that showed up were Run Maven Build, Run Maven Install, Run Maven Clean, etc. Run Maven package doesn't appear. It would really help to have a key binding for this command, thanks for your help.

like image 253
Bryan Glazer Avatar asked Jul 19 '11 20:07

Bryan Glazer


1 Answers

The approach I use in this case is to create run configurations for the goals I want (mvn package in your case) and then use key bindings to access those run configs:

  1. Bind Maven Build to your desired key
    • Note: it defaults to shift-alt-X, M
  2. Create Maven Run configurations for your desired goals like mvn package
    1. Select your project, choose run > Run Configurations...
    2. Select the current maven run configuration for your project (under Maven Build > yourProjectName)
    3. Click the copy button on the upper left to copy the run config
    4. in the name section, give a meaningful name such as "yourProject--package"
      [optionally, rename your original config to something like "yourProject--install"]
    5. In the "Goals" section, type the goals you want such as "clean package"
    6. Choose "Apply" then "close"
  3. Use Maven Build key binding, then arrow keys to select appropriate goal
    • Now, when you hit your "Maven Build" key binding, you will be prompted with a window to select your desired run configuration. This window only appears when you have more than one maven run configuration! From there press ENTER and you'll choose your package goal!
    • pressing enter will select the first maven configuration
    • use the arrow keys to select other configs
    • name your configurations such that the one you use most is at the top

Now, to execute mvn package on your project, press:

shift-alt-X, M
enter

To execute mvn clean install -DskipTests on your project, press:

shift-alt-X, M
down
down
enter


I hope that helps someone...
like image 95
gMale Avatar answered Sep 19 '22 22:09

gMale