我试图通过向它传递整数参数来使用Struts2来运行jasper。但我收到错误
cannot assign instance of net.sf.jasperreports.engine.base.JRBaseTextField to field
net.sf.jasperreports.engine.base.JRBaseParagraph.paragraphContainer of type
net.sf.jasperreports.engine.JRParagraphContainer in instance of
net.sf.jasperreports.engine.base.JRBaseParagraph
我使用的代码
parameterMap.put(parametername, param);
connection = dbc.getConnection();
JasperPrint jasperPrint = JasperFillManager.fillReport("jasper.jasper", parameterMap, connection);
JasperExportManager.exportReportToPdfFile(jasperPrint,"jasper.pdf");
请任何人帮我解决这个问题
答案 0 :(得分:2)
这是已知问题,因为see。
您可能正在使用 commons-digester 2.1
。您应该使用 1.7
版本的 commons-digester
库。
更新:
我的工作示例(独立的maven java应用程序):
public static void testReport() {
Connection connection = null;
try {
Class.forName("org.hsqldb.jdbcDriver");
String url = "jdbc:hsqldb:file:d:\\path_to_db\db_file_name";
connection = DriverManager.getConnection(url, "sa", "");
String reportSource = "d:\\path_to_jrxml\\simple.jrxml";
Map<String, Object> params = new HashMap<String, Object>();
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection);
JasperExportManager.exportReportToPdfFile(jasperPrint, "d:\\output_path\\out.pdf");
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}
pom.xml的片段:
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.1.2</version>
<exclusions>
<exclusion>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler-jdt</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>groovy</groupId>
<artifactId>groovy-all-1.0-jsr</artifactId>
<version>05</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.4</version>
<scope>runtime</scope>
</dependency>
</dependencies>
您可以尝试使用像我这样的示例应用程序来构建报表。
我认为您的问题与classpath有关。