繁体   English   中英

从 java 程序运行 build.xml

[英]running build.xml from java program

i am trying to run ant script from java program.what is the procedure to execute the program How to run build.xml from java program?

这是我试图实施的方式

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更好的解决方案

与其尝试单独启动 windows 可执行文件,不如使用 Ant API 是一种更强大、更灵活的解决方案。 ant 本身包含文档,它们不在线...

试试Runtime.getRuntime().exec("cmd /c start ant.bat"); 取自如何从我的 Java 应用程序运行批处理文件?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM