我<path id="...">
的build.xml
. 在调用编译器之前,我想验证类路径上的每个 jar/目录是否存在,并打印缺少的警告。有人知道现有的解决方案还是我需要为此编写自己的任务?
好的,我决定去做一个自定义任务。在这里,以防有人需要这样的东西:
import java.io.File;
import java.util.Iterator;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.resources.Resources;
public class CheckClasspathTask extends Task {
private Reference reference;
public CheckClasspathTask() {
}
public void setRefId(Reference reference) {
this.reference = reference;
}
public void execute() throws BuildException {
Resources resources = new Resources();
resources.setProject(getProject());
resources.add((ResourceCollection) reference.getReferencedObject());
boolean isFirst = true;
for (Iterator i = resources.iterator(); i.hasNext(); ) {
String f = i.next().toString();
if (!new File(f).exists()) {
if (isFirst) {
isFirst = false;
System.out.println("WARNING: The following entries on your classpath do not exist:");
}
System.out.println(f);
}
}
}
}