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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM