Java Code Examples for net.sf.jasperreports.engine.JasperCompileManager#compileReportToFile()

The following examples show how to use net.sf.jasperreports.engine.JasperCompileManager#compileReportToFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JReportUtils.java    From bamboobsc with Apache License 2.0 6 votes vote down vote up
/**
 * jasperreport compile jrxml 成 jasper
 * 
 * @param sourceFile		如: File[]
 * @param destDir			如: C:/report/     產生一個 test.jasper 到 C:/report/ 中
 * @return
 * @throws JRException
 */
public static String compileReportToJasperFile(File sourceFile[], String destDir) throws JRException {
	String jasperFirst = "";
	for (int ix=0; sourceFile!=null && ix<sourceFile.length; ix++) {
		File srcFile = sourceFile[ix];
		if (!srcFile.exists() || srcFile.getName().indexOf(".jrxml")==-1) {
			srcFile=null;
			continue;
		}
		//String destFileName=srcFile.getName().replaceAll(".jrxml", ".jasper");
		String destFileName=srcFile.getPath().replaceAll(".jrxml", ".jasper");
		if ("".equals(jasperFirst)) {
			jasperFirst = destFileName;
		}
		JasperCompileManager.compileReportToFile(srcFile.getPath(), destFileName);
		logger.info("out process : " + destFileName);
	}
	return jasperFirst;
}
 
Example 2
Source File: JReportUtils.java    From bamboobsc with Apache License 2.0 6 votes vote down vote up
/**
 * jasperreport compile jrxml 成 jasper
 * 
 * @param sourceFileName	如: new String[]{ "C:/report-source/test.jrxml" }
 * @param destDir			如: C:/report/     產生一個 test.jasper 到 C:/report/ 中
 * @return
 * @throws JRException
 */
public static String compileReportToJasperFile(String sourceFileName[], String destDir) throws JRException {
	String jasperFirst = "";
	for (int ix=0; sourceFileName!=null && ix<sourceFileName.length; ix++) {
		File srcFile = new File(sourceFileName[ix]);
		if (!srcFile.exists() || srcFile.getName().indexOf(".jrxml")==-1) {
			srcFile=null;
			continue;
		}
		//String destFileName=srcFile.getName().replaceAll(".jrxml", ".jasper");
		String destFileName=srcFile.getPath().replaceAll(".jrxml", ".jasper");
		if ("".equals(jasperFirst)) {
			jasperFirst = destFileName;
		}
		JasperCompileManager.compileReportToFile(srcFile.getPath(), destFileName);
		logger.info("out process : " + destFileName);
	}
	return jasperFirst;
}
 
Example 3
Source File: QueryApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public void compile() throws JRException
{
	long start = System.currentTimeMillis();
	JasperCompileManager.compileReportToFile("reports/QueryReport.jrxml", "build/reports/QueryReport.jasper");
	System.err.println("Compile time : " + (System.currentTimeMillis() - start));
}
 
Example 4
Source File: NoXmlDesignApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public void compile() throws JRException
{
	long start = System.currentTimeMillis();
	JasperDesign jasperDesign = getJasperDesign();
	JasperCompileManager.compileReportToFile(jasperDesign, "build/reports/NoXmlDesignReport.jasper");
	System.err.println("Compile time : " + (System.currentTimeMillis() - start));
}
 
Example 5
Source File: CompileServlet.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void service(
	HttpServletRequest request,
	HttpServletResponse response
	) throws IOException, ServletException
{
	ServletContext context = this.getServletConfig().getServletContext();

	response.setContentType("text/html");
	PrintWriter out = response.getWriter();

	try
	{
		JasperCompileManager.compileReportToFile(context.getRealPath("/reports/WebappReport.jrxml"));
	}
	catch (JRException e)
	{
		out.println("<html>");
		out.println("<head>");
		out.println("<title>JasperReports - Web Application Sample</title>");
		out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">");
		out.println("</head>");
		
		out.println("<body bgcolor=\"white\">");

		out.println("<span class=\"bnew\">JasperReports encountered this error :</span>");
		out.println("<pre>");

		e.printStackTrace(out);

		out.println("</pre>");

		out.println("</body>");
		out.println("</html>");

		return;
	}

	out.println("<html>");
	out.println("<head>");
	out.println("<title>JasperReports - Web Application Sample</title>");
	out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">");
	out.println("</head>");
	
	out.println("<body bgcolor=\"white\">");

	out.println("<span class=\"bold\">The JRXML report design was successfully compiled.</span>");

	out.println("</body>");
	out.println("</html>");
}