I am writing an inline javascript in ant. This script will scan a directory and output the names of files that are not up to date with respect to a given timestamp.
<script language="javascript"> <![CDATA[
importPackage(Packages.java.lang);
importPackage(Packages.org.apache.commons.io.FileUtils);
importClass(Packages.java.io.File);
importClass(Packages.java.util.Iterator);
var path = "D:\DirectoryToScan\";
var timeToCompare = buildServers.getProperty("buildStartTime");
var invocationTime = new Date(timeToCompare );
invocationTime = invocationTime.getTime();
var directoryToSearch = new File(path );
//CODE BREAKS HERE. NONE OF THE SUBSEQUENT LINES EXECUTE
var fileIterator = FileUtils.iterateFiles(directoryToSearch, new String[]{"pdf","html"} , true);
//iterate through files and directories in builtDocs folder and return false if any of the files is older than invocation time
while (fileIterator.hasNext()) {
var doc = fileIterator.next();
if ((!FileUtils.isFileNewer(doc, invocationTime))) {
return false;
}
}
]]> </script>
I have noticed that the first call to FileUtils breaks. I also tried using some simple classes but they were not accessible and looks like import statement is not working for custom classes or belong to packages that apparently are not accessible here (such as apache.tools.ant.util.FileUtils).
Is there something that i need to do here to load the classes correctly before accessing them?
The issue was resolved by including the jar file in ant.cmd file.