我面临一个问题。当我使用java调用ant.xml方法时,如何设置include的多个属性?例如,set fileset不仅包括.jar,还包括.war等等。附言:我试过用空格或逗号把它们分开,但都不管用。
antfile文件:
<?xml version="1.0" encoding="UTF-8"?>
<project name = "antcopy" default="copyFile" basedir=".">
<target name = "copyFile">
<copy todir = "${toDir}">
<fileset dir = "${srcDir}">
<include name = "${includes}"/>
<exclude name = "${excludes}"/>
</fileset>
</copy>
</target>
</project>
java文件:
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import java.io.File;
public class AntCopy {
File buildFile;
Project project;
public AntCopy(String toDir, String dir, String include, String exclude) {
buildFile = new File("src\\main\\java\\Ant\\AntCopy.xml");
project = new Project();
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
project.addBuildListener(consoleLogger);
project.setProperty("srcDir", dir);
project.setProperty("toDir", toDir);
project.setProperty("includes", include);
project.setProperty("excludes", exclude);
project.fireBuildStarted();
project.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
helper.parse(project, buildFile);
}
public void execute() {
project.executeTarget(project.getDefaultTarget());
project.fireBuildFinished(null);
}
}
主入口
public class Main {
public static void main(String[] args) {
AntCopy antCopy = new AntCopy("D:\\AntTest\\file222", "D:\\AntTest\\file111", "*.jar","");
antCopy.execute();
}
}
暂无答案!
目前还没有任何答案,快来回答吧!