Phate
Phate

Reputation: 6612

Is it possible to programmatically call a maven build?

I have a project that is calling a maven plugin (open-api-generator) to make a build based on an api specification. I don't want to share the project but I'd like to create a jar that somewhat simulate a "mvn compile" using an internal maven pom.xml.

Is this possible?

Upvotes: 2

Views: 873

Answers (2)

Amit kumar
Amit kumar

Reputation: 2694

Code :

MavenCli obj = new MavenCli();
obj.doMain(new String[]{"compile"}, "project_dir", System.out, System.out);
P

Add :

  1. maven-embedder
  2. aether-connector-wagon and
  3. wagon-http-lightweight

dependencies in your pom.xml.

Upvotes: 1

Maxi
Maxi

Reputation: 443

Programatically it is possible to call the Shell command. For example with:

ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("bash", "-c", "mvn compile /foo/bar");

Upvotes: 0

Related Questions