Возможно ли определить и выполнить сложную задачу ant в java-приложении? Что мне нужно сделать, так это:
<copy todir="dirDest">
<fileset dir="sourceDir">
<exclude name="exFile.ext" />
<exclude name="dirEx" />
</fileset>
</copy>
Пример объясняет, что мне нужно сделать в моем приложении Java, или, скорее, скопировать содержимое каталога в другой с некоторым исключением. Выполнение одной задачи очень просто, но я не могу найти учебник для моего примера.
Я отвечаю на мой вопрос...
Прочитав документы кода класса apache ant, я нашел, как построить задачу:
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 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();