Is it possible to call Maven goals from Java, for instance, can I do the equivalent of:
mvn clean package
from a Java class?
thanks, Nick
How to Run Web Application. Create a run configuration by click "Run → Run Configurations", select Maven Build and click "New launch configuration", type Name "OpenMRS", select working directory to be the root of webapp project, type goal "jetty:run" and save. Now you select "OpenMRS" and run or debug it.
A Maven plugin is a group of goals; however, these goals aren't necessarily all bound to the same phase. As we can see, the Failsafe plugin has two main goals configured here: integration-test: run integration tests. verify: verify all integration tests passed.
absolutely, you need to use the Maven Embedder API.
Updated link is http://maven.apache.org/ref/3-LATEST/maven-embedder/index.html
This is easy :)
Java code
MavenCli cli = new MavenCli();
cli.doMain(new String[]{"clean", "package"}, "project_dir", System.out, System.out);
Project configuration:
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-wagon</artifactId>
<version>0.9.0.M2</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
Fully working example: https://github.com/mariuszs/maven-cli-example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With