java - 在java中定义并执行组合ant任务

标签 java ant

是否可以在 java 应用程序中定义并执行组合的 ant 任务? 我需要做的是这样的:

<copy todir="dirDest">
  <fileset dir="sourceDir">
    <exclude name="exFile.ext" />
    <exclude name="dirEx" />
  </fileset>
</copy>

这个例子解释了我需要在我的java应用程序中做什么,或者更确切地说,将一个目录内容复制到另一个目录中,但有一些异常(exception)。 单个任务的执行非常simple但我找不到关于我的示例的教程。

最佳答案

我回答我的问题...

看完apache ant类code documents ,我已经找到了如何构建任务:

import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Copy;
import org.apache.tools.ant.types.FileSet;

//Create the new copy class
Copy copier = new Copy();
//Set the target directory wrapped into File object
copier.setTodir(new File("my/target/directory"));
//The project's definition is requested for the execution of Copy
copier.setProject(new Project());

//Before run its request to define the FileSet object
FileSet fs = new FileSet();

//Now setup the base directory to copy
fs.setDir(new File("my/source/directory"));
//If its require, define the inner file or directory to exclude from the copy action
fs.setExcludes("fileExcluded");
fs.setExcludes("directory/to/exclude");

//Link the FileSet to copy
copier.addFileset(fs);
//And go!
copier.execute();

关于java - 在java中定义并执行组合ant任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29303504/

相关文章:

Javadoc 不为继承的方法生成注释

android - build.xml 和 project_name.xml 的区别

java - 使用ant编译时Aspectj不工作

java - Android 应用程序在模拟器上运行,在手机上崩溃

java - Android更新数组内容/内容

java - 小程序的安全问题

android - 如何链接 Ant 中的外部 jar?

android - 通过主 ANT 构建文件构建多个 android 项目

java - 如何使用监护人项目在android中使用FFMPEG连接视频

java连接与mysql错误