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

how to create a .jasper file from .xml


2005 IR Help

Recommended Posts

By: Kat brekher - kbrekher

how to create a .jasper file from .xml

2004-05-27 07:12

Hi,

inside my java code I'm able to create .xml file put it out in a dir, compile it and then and then view.

But I need to be able to create and write out .jasper class into a dir so I can save that file.

 

This is what I use to compile my .xml

JasperDesign jasperDesign = JasperManager.loadXmlDesign(reportFile.getAbsolutePath());

JasperReport jasperReport = JasperManager.compileReport(jasperDesign);

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);

 

How can I generate .jasper file (not using iReport or something else like that)

 

 

 

 

 

By: C-Box - c-box

RE: how to create a .jasper file from .xml

2004-05-27 08:31

So I guess you want to store the compiled report after you loaded and compiled it, isn't it?

 

 

So I'd do it...

 

 

File reportFile = new File("C:/test/testreport.xml"); //load Report into FileObject

 

String strJasperFileName = reportFile .getAbsolutePath().toLowerCase().replaceAll(".xml", ".jasper"); // build up the JasperFileName as String

 

JasperReport jasperReport = JasperCompileManager.compileReport(reportFile.getAbsolutePath());// compile the report from FileName

 

if (saveReportAsJasperFile(jasperReport ,strJasperFileName))

{

// do what you want after saving it

}

...

 

private boolean saveReportAsJasperFile(JasperReport pReport, String pDestFile){

boolean myBool = false;

try {

if (pReport != null) {

JRSaver.saveObject(pReport, pDestFile);

File myFile = new File(pDestFile);

if (myFile.exists()) {

myBool = true;

System.out.println("File '"+pDestFile+"' successfully saved!");

}

}

}

catch (Exception ex) {

System.out.println("Error in saving report to JasperFile:" + ex);

}

return myBool;

}

 

 

hth

C-Box

 

 

 

 

By: Kat brekher - kbrekher

RE: how to create a .jasper file from .xml

2004-05-28 08:50

Thanks a lot, That's exactely what I needed. (as a temp solution I used JasperManager.compileReportToFile but did not want to compile twice)

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