简体   繁体   English

编译sales.jrxml文件后,它会创建null.jasper而不是sales.jasper

[英]After Compiling sales.jrxml file it create null.jasper instead of sales.jasper

I am using the following code to print a report: 我使用以下代码打印报告:

    JasperPrint jasperPrint = null;

    try {
        JasperCompileManager.compileReportToFile("C:\\Nevro\\reports\\salesDetails.jrxml");
        jasperPrint = JasperFillManager.fillReport("C:\\Nevro\\reports\\salesDetails.jasper", new HashMap(),
                new JRTableModelDataSource(itemTable.getModel()));
        JasperViewer jasperViewer = new JasperViewer(jasperPrint);
        jasperViewer.setVisible(true);
    } catch (JRException ex) {
        Logger.getLogger(Invoice.class.getName()).log(Level.SEVERE, null, ex);
    }

In the location C:\\Nevro\\reports\\ I have created salesDetails.jrxml . 在位置C:\\Nevro\\reports\\我创建了salesDetails.jrxml Then in Java code I read the file and compile it. 然后在Java代码中我读取文件并进行编译。 I expected to create compiled file as salesDetails.jasper but it create only null.jasper . 我希望将编译后的文件创建为salesDetails.jasper但它只创建null.jasper

Can any one give me a reason and solution to sort this out? 任何人都可以给我一个理由和解决方案来解决这个问题吗?

The filename is generated by this line of code within the Jasper library: 文件名由Jasper库中的这行代码生成:

File destFile = new File(sourceFile.getParent(), jasperDesign.getName() + ".jasper");

It takes the path of the jrxml file and generates the output file based on the name of your report (configured in the XML). 它采用jrxml文件的路径,并根据报告的名称(在XML中配置)生成输出文件。 In your case the report has no name, so you get null.jasper . 在您的情况下,报告没有名称,因此您获得null.jasper

You can also give name of .jasper file explicitly like, 你也可以明确地给出.jasper文件的名称,如,

JasperCompileManager.compileReportToFile(
                our_jasper_template.jrxml",//the path to the jrxml file to compile
                our_compiled_template.jasper");//the path and name we want to save the com

So the above code will generate .jasper file at same location where .jrxml file exists. 因此,上面的代码将在.jrxml文件所在的同一位置生成.jasper文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM