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版本以下的

  • 相关阅读:
    HTML目录
    Java目录
    高级Swing——列表
    Java Web目录
    mongodb目录
    MySQL目录
    基于C++11的线程池
    数据库架构的演变
    cocos2dx-3.0(14)------SpriteBatchNode与SpriteFrameCache加快渲染
    cocos2d-x 托付模式的巧妙运用——附源代码(一)
  • 原文地址:https://www.cnblogs.com/xhf-wonder/p/9055051.html
Copyright © 2011-2022 走看看