栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何从Java程序运行mvn命令?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何从Java程序运行mvn命令?

我设法使用以下代码运行mvn :(我使用此命令:Runtime.getRuntime()。exec(cmd);)

    import java.io.*;    import java.util.ArrayList;    public class RunMvnFromJava     { static public String[] runCommand(String cmd)throws IOException{     // The actual procedure for process execution:     //runCommand(String cmd);     // Create a list for storing output.     ArrayList list = new ArrayList();     // Execute a command and get its process handle     Process proc = Runtime.getRuntime().exec(cmd);     // Get the handle for the processes InputStream     InputStream istr = proc.getInputStream();     // Create a BufferedReader and specify it reads     // from an input stream.     BufferedReader br = new BufferedReader(new InputStreamReader(istr));     String str; // Temporary String variable     // Read to Temp Variable, Check for null then     // add to (ArrayList)list     while ((str = br.readLine()) != null)          list.add(str);         // Wait for process to terminate and catch any Exceptions.  try {       proc.waitFor();       }  catch (InterruptedException e) {      System.err.println("Process was interrupted");       }  // Note: proc.exitValue() returns the exit value.  // (Use if required)  br.close(); // Done.  // Convert the list to a string and return  return (String[])list.toArray(new String[0]);}// Actual execution starts here public static void main(String args[]) throws IOException {     try     {         // Run and get the output.         String outlist[] = runCommand("mvn integration-test -DskipTests -P interactive -e");         // Print the output to screen character by character.         // Safe and not very inefficient.         for (int i = 0; i < outlist.length; i++)  System.out.println(outlist[i]);     }        catch (IOException e) {          System.err.println(e);      } }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/464116.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号