java - 从 java 程序运行 build.xml

标签 java ant

我正在尝试从java程序运行ant脚本。执行该程序的过程是什么 如何从java程序运行build.xml?

这是我尝试实现的方式

Process proc = rt.exec("ant -buildfile D:ant\\trail");

问候, 技术人员

最佳答案

查看此处Execute Ant From Your Application 看看这个例子:

      Project project = new Project();
      project.init();
      DefaultLogger logger = new DefaultLogger();
      logger.setMessageOutputLevel(Project.MSG_INFO);
      logger.setErrorPrintStream(System.err);
      logger.setOutputPrintStream(System.out);
      project.addBuildListener(logger);

      File buildFile = new File("buildhtml.xml");
      ProjectHelper.configureProject(project, buildFile);
      project.setProperty("ant.file", buildFile.getAbsolutePath());
      project.setProperty("item", "ant");
      project.setProperty("inputdir", "src/items/ant");
      project.setProperty("outputdir", "build/items/ant");
      project.setProperty("graphics.prefix", "../../");
      try {
         project.executeTarget("checkifuptodate");
      } catch(Exception e) {System.err.println(e.getMessage());}
      // rest of program goes here

这是比调用 Runtime.exec 更好的解决方案

关于java - 从 java 程序运行 build.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6663696/

相关文章:

java - 将 int 数组的二进制表示形式的 1 的数量存储在另一个数组中

java - Cobertura仪器仪表

java - 需要使用 sudo 用户执行脚本文件 - 从 teamcity 运行

java - 从 Eclipse 的 CompilationUnit 生成字节码

java - 在 eclipse 中构建项目,但不是从终端/jenkins - 使用 Ant

Ant 等价于 nant.onsuccess/nant.onfailure

android - 使用 ANT 选择性地将 API 编译到您的 Android 可执行文件中

java - 使用 java 或 javafx 打印 html 文件

java - 如何确定 Java 8 元空间的理想大小

java - 谷歌应用引擎 : couldn't start server - jetty