Jump to content
We've recently updated our Privacy Statement, available here ×

compiling report templates


Recommended Posts

By: sid - z036816

compiling report templates

2006-06-25 17:54

I'm going to include jasperreports in my web application. I have a question where to put the following lines

System.setProperty("jasper.reports.compile.temp",

context.getRealPath("/reports/"));

 

JasperCompileManager.compileReportToFile(

getServletContext().getRealPath(

"/reports/BasicReport.xml"));

 

I suppose this has to be executed only once. I'm wondering whats the best practice? to place it in servlets init() method or manually compile and put the .jasper file in EAR package

 

Thanks in advance

 

 

By: vertebreaker - vertebreaker

RE: compiling report templates

2006-06-26 10:04

I have the .jrxml and .jasper (compiled with jasperassistant or iReports) in the ear.

It tries to load the .jasper when executing a report, but it compiles if no .jasper is found (done with code).

It takes some time compiling.

 

 

By: sid - z036816

RE: compiling report templates

2006-06-26 18:29

I use ant to build EAR file. how do u compile with jasperassistant in build.xml? is there an ant task? can u put some code please.

 

I have an idea of writing java class to compile xml , then i would compile that during the ear build. does that make sense?

 

 

 

 

By: vertebreaker - vertebreaker

RE: compiling report templates

2006-06-27 12:59

I can´t see an ant task, I haven´t done it.

I just install jasperassistant and use it, preview to compile to .jasper.

 

But in case, I make compile the .jrxml when the .jasper is not found. Then I use a java class.

 

private String compilar(){

 

try {

File classpath= new File(this.servlet.getServletConfig().getServletContext().getRealPath("/WEB-INF/"));

 

System.setProperty("jasper.reports.compile.class.path",classpath.getPath()+"/lib/jasperreports-1.0.2.jar"+ System.getProperty("path.separator") + classpath.getPath()+"/classes/");

System.out.println("Compilando reporte: "+reporte.getNombreReporteXML());

reporte.setNombreReporteJasper(JasperCompileManager.compileReportToFile(reporte.getNombreReporteXML()));

 

} catch (JRException e) {

e.printStackTrace();

} catch (Exception e){

 

}

return reporte.getNombreReporteJasper();

}

 

Where reporte.nombreReporteJasper is String containing the .jasper file name, and reporte.nombreReporteXML is a String containing the .jrxml file name....

Something like:

File reportToCompile= new File(this.servlet.getServletConfig().getServletContext().getRealPath("/public/reports/MyReport.jrxml"));

reporte.setNombreReporteXML(reportToCompile.getPath());

 

Did it help?

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...