Jump to content
Changes to the Jaspersoft community edition download ×

How to load .jasper instead of .jrxml


nkamir

Recommended Posts

Hi,

Right now I'm compiling and loading my jasper report from .jrxml file as following? How do I load my reports from a pre-compiled .jasper file?

 

Code:



Also, How do I use this absolute path with a reletive path?

 

Appreciated....

 

 



Post Edited by Nasir Amir at 04/02/09 18:38
Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Nice, the loadObject works just fine, Thanks.

Now, that document says:
"A relative pathname that does not specify a drive has no prefix."

but I get FileNotFoundException while trying it as following:
 
the absolute path of the jasper object is:
D:/Working/MyApp/src/MyApp/MyReportsJrxml/AccountActivityReport.jasper

the absolute path of the java class  is:
D:/Working/MyApp/src/MyApp/MyReports/AccountActivityReport.class

I'm trying to access it as
../MyReportsJrxml/AccountActivity.jasper";
 

what could be the issue?

Link to comment
Share on other sites

What you want to export file type?

Html?xls?pdf?

This is my test code,export fill type is html,and it run successful.

  String reportFilePath = root_path
    + "WEB-INF/classes/com/sunshine/jasper/report.jasper";

JasperReport report = (JasperReport) JRLoader.loadObject(reportFilePath);
   JasperPrint jasperPrint = JasperFillManager.fillReport(report,null, conn);
      
   JRHtmlExporter exporter = new JRHtmlExporter();
   req.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrint); 
   exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,"image?image=");   
   exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
   exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
   exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "GBK");
   exporter.exportReport();

 

Hope help you.

Link to comment
Share on other sites

 
Actually, I'm able to generate my reports with absolute path, but I can't figure out how to use relative path to do the same thing.
 

The class that is calling the report file is:
D:/MyApplication/src/App/MyReports/AccountActivityReport.class

and the report file is:
D:/MyApplication/src/App/MyReportsJrxml/AccountActivityReport.jasper

  
I wanna call this report as:
../MyReportsJrxml/AccountActivity.jasper"
 
 
Appreciated...
 
 
 

 



Post Edited by Nasir Amir at 04/06/09 13:13
Link to comment
Share on other sites

Again, relative paths are relative to the JVM's current user directory, and not to the class that calls JasperReports methods.

If you want to specify paths as relative to your class, you'll have to call Class.getResource() yourselft and pass the result URL to JasperReports.

Regards,

Lucian

Link to comment
Share on other sites

  • 3 years later...

I use InputStreams to do the load that way I can have it in either class path or physical file or some other stream source.

InputStream jasperStream = getClass().getResourceAsStream("/Foo.jasper");
JasperReport report = (JasperReport) JRLoader.loadObject(jasperStream);

Link to comment
Share on other sites

  • 3 years later...

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...