美文网首页
通过java执行maven命令

通过java执行maven命令

作者: 追风还是少年 | 来源:发表于2023-08-04 22:45 被阅读0次

    引入依赖

            <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 {
    
            }
    }
    

    相关文章

      网友评论

          本文标题:通过java执行maven命令

          本文链接:https://www.haomeiwen.com/subject/gklbpdtx.html