zoukankan      html  css  js  c++  java
  • ant target ----build.xml如何配置及注意事项

    运行方式

    1. 通过ant 直接运行, 如:ant app (其中app是target的名字<target name="app>)
    2. java代码运行,java代码运行前准备ant-launcher.jar, ant.jar, apache-xml-xerces.jar

    初始化project
    public void init(String buildFile, String baseDir) throws Exception {
    project= new Project();
    project.init();
    DefaultLogger consoleLogger = new DefaultLogger();
    consoleLogger.setErrorPrintStream(System.err);
    consoleLogger.setOutputPrintStream(System.out);
    consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
    project.addBuildListener(consoleLogger);
    // Set the base directory. If none is given, "." is used.
    if (baseDir == null) {
    baseDir = new String(".");
    }
    project.setBasedir(baseDir);
    if (buildFile == null) {
    buildFile = new String(ConnectCvs.BUILDPATH);
    }
    project.setBaseDir(new File(ConnectCvs.BASEDIR));
    ProjectHelper.configureProject(project, new File(buildFile));
    }

    运行相应的target
    public void runTarget(String target) throws Exception {
    if (project == null) {
    throw new Exception("No target can be launched because the project has not been initialized. Please call the 'init' method first !");
    }
    if (target == null) {
    target = project.getDefaultTarget();
    }
    // Run the target
    project.executeTarget(target);
    }

    给build.xml里的参数赋值

    1. 通过ant: ant app -Dfilesource="aaa" (其中app是target的name, filesource是要被赋值的参数, aaa值,注:D和参数不能有空格
      2. java传参: project.setProperty("filesource", StringUtil.join(syncFiles.toArray(), ","))

    当传入的值是有多个需要遍历,先对其分割, 如:
    有时候对单个数据处理在标签里不能用,因为有的标签不能在标签中使用,故可以通过target在外部处理

    使用foreach的前提

    1. 准备ant-contrib-1.0b3.jar
      2. 配置




    注:这个jar包只支持ant1.6版本以下的

  • 相关阅读:
    P3469 [POI2008]BLO-Blockade
    洛谷P2342 叠积木
    洛谷 P1197 [JSOI2008]星球大战
    洛谷P1967 货车运输
    洛谷P2812校园网络【Network of Schools加强版】
    洛谷P3003 苹果交货Apple Delivery
    luogu Eat the Trees
    插头DP模板
    [NOIP2017] 宝藏
    LOJ6268拆分数
  • 原文地址:https://www.cnblogs.com/xhf-wonder/p/9055051.html
Copyright © 2011-2022 走看看