title: How do I programmatically invoke a maven build with my Eclipse plug-in project?
body: <p>I am currently writing an Eclipse plug-in that allows users to create Maven projects with some template Java code already included.</p>
  
  <p>I'm trying to have some custom controls to <code>mvn clean build</code> or <code>mvn clean deploy</code> a project. So far I have a <em>Custom Package</em> and a <em>Custom Deploy</em> <code>IHandler</code> tied to some menu contributions. They use <strong>Maven Invoker</strong> to build it something like this:</p>
  
  <pre><code>MessageConsole console = ...
  console.clearConsole();
  console.activate();
  
  MessageConsoleStream consoleOut = console.newMessageStream();
  consoleOut.setActivateOnWrite(true);
  
  try (
      PrintStream stdout = new PrintStream(consoleOut, true))
  {
      // Invoke Maven
      InvocationRequest request = new DefaultInvocationRequest();
      request.setPomFile(new File(project.getFile("pom.xml").getLocation().toOSString()));
      request.setGoals(Arrays.asList(goals));
  
      Invoker invoker = new DefaultInvoker();
      invoker.setOutputHandler(new PrintStreamHandler(stdout, true));
      invoker.execute(request);
  } catch (MavenInvocationException e) {
      ...
  }
  </code></pre>
  
  <p>This worked fine on my Windows 7 environment but had a number of issues when I tested it on my Mac environment, namely <strong>nothing printed to console</strong> and required that <strong>M2_HOME MUST be set</strong>. There were other little problems and I really felt like I was re-inventing the wheel, and that I should be able to leverage Eclipse existing m2e functionality.</p>
  
  <p>So I started to look into <code>ILaunchConfigurationDelegate</code> and found the <code>MavenLaunchDelegate</code> class. It has <em>restriction warnings</em> but I'm not concerned. I also found the <code>ExecutePomAction</code> which brings up the very familiar Maven Build run configuration panel, but I want to use my own custom shortcut.</p>
  
  <p>I was hoping to write my own <code>ILaunchShortcut</code> with only one choice: <em>package</em> or <em>deploy</em>, and invoke an appropriate Maven build from both this shortcut and my custom handlers. The problem is... <strong>I'm lost</strong>.</p>
  
  <p>I'm looking for advice or resources on <strong>the best way to invoke a maven build programmatically from an Eclipse plugin</strong>.</p>