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和参数不能有空格
    1. java传参: project.setProperty("filesource", StringUtil.join(syncFiles.toArray(), ","))

当传入的值是有多个需要遍历,先对其分割, 如:有时候对单个数据处理在

使用foreach的前提

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

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

猜你喜欢

转载自www.cnblogs.com/xhf-wonder/p/9055051.html