How to run maven from java?

I want to execute maven command from Java for development of a plugin. I tried maven-embedder but looks like it is now not supported. Is someone aware of some other tool which can be used?


A simple invocation API : maven-invoker.

Project documentation :

Usage :

InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile( new File( "/path/to/pom.xml" ) );
request.setGoals( Arrays.asList( "clean", "install" ) );

Invoker invoker = new DefaultInvoker();
invoker.execute( request );

Use Maven Embedder

Maven embedder is still supported and easy to configure, so this is better option for you.

Java code
MavenCli cli = new MavenCli();
cli.doMain(new String[]{"clean", "install"}, "project_dir", System.out, System.out);
Project configuration

Fully working example:

Maven embedder is indeed no longer supported (only hudson still uses it). But, as in hudson, there are several other ways to run maven. You could simply run maven as an external program:

Runtime.getRuntime().exec("mvn clean install");

Or you could consider creating an ant script for maven. This script could then be called either as an external program or (if you need more control) adding ant to your classpath and calling the Antrunner.


Maven embedder is now supported again so that is your best option.

Need Your Help

How to time an Asychronous HttpWebRequest?

c# httpwebrequest

I am wondering if there is a way to time an Asyhcnronous WebRequest.

Stop listening to a port

java ssl websphere port

I have a application that accepts SSL connections on a particular port. When I stop the application from the Websphere Administrative Console and then start it again, I get an exception that compla...