Skip to content

Instantly share code, notes, and snippets.

@dagvadorj
Created October 25, 2012 03:16
Show Gist options
  • Save dagvadorj/3950235 to your computer and use it in GitHub Desktop.
Save dagvadorj/3950235 to your computer and use it in GitHub Desktop.
Compiling jrxml to binary jasper reports
import java.io.File;
import java.util.Collection;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
/*
* @author Dagvadorj Galbadrakh <dagvadorj@gmail.com>
*/
public class JasperCompiler {
public static void main(String[] args) throws JRException {
// Get currently running directory
String currentPath = System.getProperty("user.dir");
System.out.println("Current path is: " + currentPath);
// Go to directory where all the reports are
File rootDir = new File(currentPath + "/WebContent/reports");
// Get all *.jrxml files
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");
// Actual compiling
JasperCompileManager.compileReportToFile(file.getAbsolutePath(),
"WebContent/reports/" + file.getName() + ".jasper");
System.out.println("Compiling: completed!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment