The Jasper Report design file specifies the layout and appearance of the report and they works best with the .JRXML extension files. We use iReport to deal with the jrxml reports but sometimes we need to compile JRXML file through our java code. We can do this with the help of net.sf.jasperreports package.
Change the path of the JRXML and jasper files in below code and run this code to compile any JRXML file and generate jasper report.
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
public class compileJasper{
public static void main(String[] args)
{
// below code will compile the jasper file which is located on path given below
try {
JasperCompileManager.compileReportToFile("PathOfTheJRXMLFile(which needs to be compiled)" ,"PathOfJasperFile(Where to save generated jasper file)");
} catch (JRException e) {
}
}
}
Change the path of the JRXML and jasper files in below code and run this code to compile any JRXML file and generate jasper report.
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
public class compileJasper{
public static void main(String[] args)
{
// below code will compile the jasper file which is located on path given below
try {
JasperCompileManager.compileReportToFile("PathOfTheJRXMLFile(which needs to be compiled)" ,"PathOfJasperFile(Where to save generated jasper file)");
} catch (JRException e) {
}
}
}
No comments:
Post a Comment