Skip to content

Instantly share code, notes, and snippets.

@dagvadorj
Created October 9, 2012 16:26
Show Gist options
  • Save dagvadorj/3859868 to your computer and use it in GitHub Desktop.
Save dagvadorj/3859868 to your computer and use it in GitHub Desktop.
Find and compile all Jasper reports
import java.io.File;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
public class JasperCompiler {
public static void main(String[] args) throws JRException {
String currentPath = System.getProperty("user.dir");
System.out.println("Current path is: " + currentPath);
File rootDir = new File(currentPath + "/reports");
Collection<File> files = FileUtils.listFiles(rootDir, new RegexFileFilter("^(.*\\.jrxml)"), TrueFileFilter.INSTANCE);
for (File file : files) {
System.out.println("Compiling: " + file.getAbsolutePath());
System.out.println("Output: " + file.getName() + ".jasper");
JasperCompileManager.compileReportToFile(file.getAbsolutePath(), "src/reports/" + file.getName() + ".jasper");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment