gpt4 book ai didi

java - 贾斯珀报告 : calling report from jar

转载 作者:行者123 更新时间:2023-11-30 04:08:11 25 4
gpt4 key购买 nike

我正在使用 JasperReports 4.7.1 插件 for NetBeans 7.2 从 mysql 数据库生成报告当我从 ide 运行应用程序时,没有发现任何问题,接受此警告:

log4j:WARN No appenders could be found for logger (net.sf.jasperreports.engine.xml.JRXmlDigesterFactory).
log4j:WARN Please initialize the log4j system properly.

但是报告生成并正确查看。

问题是,当我清理并构建应用程序,然后从 jar 文件中调用它时,报告不会生成,也不会给我任何异常,只是没有查看报告,其他一切都正常?

这是我在 JasperViewer 中查看报告的函数:

public void printInvoice(int invid) throws IOException {
try {
String sql = "SELECT\n" +
" ordersdetails.`ITEMNAME` AS ordersdetails_ITEMNAME,\n" +
" ordersdetails.`AMOUNT` AS ordersdetails_AMOUNT,\n" +
" ordersdetails.`PRICE` AS ordersdetails_PRICE,\n" +
" invoices.`INVOICEID` AS invoices_INVOICEID,\n" +
" invoices.`CUSTOMER` AS invoices_CUSTOMER,\n" +
" invoices.`THEDATE` AS invoices_THEDATE,\n" +
" invoices.`COST` AS invoices_COST\n" +
"FROM\n" +
" `invoices` invoices RIGHT OUTER JOIN `ordersdetails` ordersdetails ON invoices.`INVOICEID` = ordersdetails.`INVOICE` where invoices.invoiceid=" + invid;

InputStream in = this.getClass().getResourceAsStream("/reports/invoice.jrxml");

JasperDesign jd = JRXmlLoader.load(in);

JRDesignQuery q = new JRDesignQuery();
q.setText(sql);
jd.setQuery(q);

JasperReport jasp_rep = JasperCompileManager.compileReport(jd);

JasperPrint jasp_print = JasperFillManager.fillReport(jasp_rep, null, mc.getConnection());
JasperViewer.viewReport(jasp_print, false);
} catch (JRException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
System.out.println(e);
}
}

最佳答案

可能从错误的位置加载报告,尝试相对路径:

InputStream in = this.getClass().getResourceAsStream("reports/invoice.jrxml");

这意味着报表文件夹中存在invoice.jrxml,并且该文件夹与调用getResourceAsStream 的类(this.getClass()) 处于同一级别。

此外,您可以使用

绕过警告
org.apache.log4j.BasicConfigurator.configure();

在程序开始时。

关于java - 贾斯珀报告 : calling report from jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20251307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com