引入依赖
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>3.0.1</version>
</dependency>
public static main(){
// compile、deploy
String cmd = "compile";
InvocationRequest request = new DefaultInvocationRequest();
request.setUserSettingsFile(new File(sourcePath, "settings.xml"));
request.setPomFile(new File(sourcePath, "pom.xml"));
request.setGoals(cmd);
request.setBaseDirectory(new File(sourcePath));
List<String> outList = new ArrayList<>();
InvocationOutputHandler handler = outList::add;
request.setOutputHandler(handler);
// request.setErrorHandler(handler);
Invoker invoker = new DefaultInvoker();
//maven的位置
invoker.setMavenHome(new File(mavenPath));
if(execute.getExitCode() != 0){
} else {
}
}
网友评论