gpt4 book ai didi

java - JasperReports 类路径

转载 作者:太空宇宙 更新时间:2023-11-04 08:29:23 25 4
gpt4 key购买 nike

我想将 .jrxml 文件包含在我的 NetBeans swing 项目中。我使用 NetBeans 7.0.1。我在源包内创建了一个名为“rep”的包,并创建了一个名为“rp.jrxml”的简单 .jrxml 文件。我已在 NetBeans 中安装了 iReport 插件。当我设置外部 .jrxml 文件时,它会显示(“D:/MyReports/firstreport.jrxml”),但当我设置 NetBeans 包路径时,它不会显示。这是我的代码。

try {
String reportSource="/rep/rp.jrxml"; //and also "rep/rp.jrxml" is used.no result.
Map<String, Object> params = new HashMap<String, Object>();
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
JasperViewer.viewReport(jasperPrint, false);
} catch (Exception e) {e.printStackTrace();
}

然后报如下错误;

net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: rep\rp.jrxml (The system cannot find the path specified)

如何将 jrxml 文件保留在我的 NetBeans 项目中并在项目中使用 jrxml 文件?

最佳答案

这段代码对我有用:

public class TestJasper {

public static void main(String[] args) {
try {
String reportSource = "resources/report1.jrxml";
Map<String, Object> params = new HashMap<String, Object>();
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
JasperViewer.viewReport(jasperPrint, false);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}

我的项目结构:

build    classes        TestJasper.classdist nbprojectresources    report1.jrxml src    TestJasper.java 

UPDATED:
For solving net.sf.jasperreports.engine.JRException: No report compiler set for language : null problem you can try to set groovy report language and add groovy-all-jdk14 library to classpath.
You can get groovy library here.

The sample of report header with language set to groovy:

<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"
...
language="groovy"
...>

关于java - JasperReports 类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7823756/

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