Hi Here is some code snippet that launches a maven goal. (It is easy to for instance launch an Ant target, it is just another launch configuration that must be used) This snippet does not really has any dependency to the m2eclipse plugin. import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.ILaunchesListener2; import org.eclipse.jface.operation.IRunnableWithProgress; public class Maven2Runner { private static final String MAVEN_LAUNCH_CONFIG_TYPE = "org.maven.ide.eclipse.Maven2LaunchConfigurationType"; //$NON-NLS-1$ /** * Run a maven goal for the project. After the goal has been run, the * project is refreshed * * @param project * @param mavenGoalString */ public static void runMavenGoal(final IProject project, final String mavenGoalString) { final ILaunchConfigurationType type = DebugPlugin.getDefault().getLaunchManager() .getLaunchConfigurationType(MAVEN_LAUNCH_CONFIG_TYPE); //$NON-NLS-1$ final String launchName = project.getName(); IRunnableWithProgress runnable = new IRunnableWithProgress() { @SuppressWarnings("unchecked") public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { monitor.beginTask("Running maven goal '" + mavenGoalString + "'", 100); ILaunchConfigurationWorkingCopy config = null; config = type.newInstance(null, launchName); List options = new ArrayList(); config.setAttribute( "org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND", true); config.setAttribute("M2_PROPERTIES", options); config.setAttribute("org.eclipse.jdt.launching.WORKING_DIRECTORY", "${workspace_loc:/" + project.getName() + "}"); config.setAttribute("M2_GOALS", mavenGoalString); config.setAttribute("M2_PROFILES", ""); // Launch the goal ILaunch launch = config.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor()); // add listener so the project can be refreshed later when the maven // goal is terminaded DebugPlugin.getDefault().getLaunchManager().addLaunch(launch); LaunchesListener.PostLaunchAction pla = new LaunchesListener.PostLaunchAction() { public void execute() throws Exception { project.refreshLocal(IResource.DEPTH_INFINITE, null); } }; ILaunchesListener2 launchesListener = new LaunchesListener(launch, pla); DebugPlugin.getDefault().getLaunchManager().addLaunchListener( launchesListener); monitor.worked(100); } catch (CoreException ce) { // TODO } } }; // Launch the task with progress try { Progress progress = new Progress(MyPlugin.getShell(), runnable); progress.run(); } catch (InvocationTargetException ite) { // TODO } catch (InterruptedException ie) { // TODO } } This code can be called from a context menu item i.e. an org.eclipse.ui.actions.ActionDelegate implmentation of your own. Cheers Lucas On 12/21/2010 08:27 AM, Gajo Csaba wrote: Hi, --
Lucas Persson | Principal Member of Technical Staff Phone: +4684773644 | | | Mobile: +46730946656 Oracle Communications Platform ORACLE Sweden | Folkungagatan 122 | 116 30 Stockholm Oracle Svenska AB, Kronborgsgränd 17, S-164 28 KISTA, reg.no. 556254-6746 Oracle is committed to developing practices and products that help protect the environment |
- m2eclipse plugin builder or launcher Gajo Csaba
- Re: m2eclipse plugin builder or launcher Anders Hammar
- Re: m2eclipse plugin builder or launcher Lucas Persson
- Re: m2eclipse plugin builder or launcher Gajo Csaba