我正在嘗試學習JasperReports。到目前爲止,我已經發現JasperReports可以與NetBeans集成,爲此,我使用了幾個教程,但無法獲得正確的代碼。我想手動創建報告。手動創建示例Jasper報告
我創建示例應用程序,它包含的代碼:
import java.util.HashMap;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
public class JavaApplication7 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String reportSource = "./report.temp.result/newXMLDocument.xml";
String reportDest = "./report.template/HelloReportWorld.html";
HashMap<String, Object> params = new HashMap<String, Object>();
try
{
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint =
JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
JasperExportManager.exportReportToHtmlFile(jasperPrint, reportDest);
JasperViewer.viewReport(jasperPrint);
}
catch (JRException ex)
{
ex.printStackTrace();
}
我也創建包含的代碼
<?xml version="1.0"?>
<!DOCTYPE jasperReport
PUBLIC "-//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="HelloReportWorld">
<detail>
<band height="200">
<staticText>
<reportElement x="0" y="0" width="500" height="20"/>
<text><![CDATA[Hello Report World!]]></text>
</staticText>
</band>
</detail>
</jasperReport>
這是XML文件作爲我的模板樣本文件在教程中閱讀xml文件可用於創建碧玉報告(它減緩編譯過程)----是好的
我已經使用空文件的c使用相同的代碼重新使用.jrxml,但我認爲我可能會丟失XML設計文檔,並且我無法弄清楚從哪裏獲得該xml設計文檔,以及在netbeans中將其添加到哪裏
我試圖運行主文件,以獲得輸出,但我得到的錯誤下面的列表
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at net.sf.jasperreports.engine.util.JRLoader.<clinit>(JRLoader.java:68)
at net.sf.jasperreports.engine.JRPropertiesUtil.loadProperties(JRPropertiesUtil.java:99)
at net.sf.jasperreports.engine.DefaultJasperReportsContext.initProperties(DefaultJasperReportsContext.java:94)
at net.sf.jasperreports.engine.DefaultJasperReportsContext.<init>(DefaultJasperReportsContext.java:71)
at net.sf.jasperreports.engine.DefaultJasperReportsContext.<clinit>(DefaultJasperReportsContext.java:59)
at net.sf.jasperreports.engine.JasperCompileManager.getDefaultInstance(JasperCompileManager.java:84)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:459)
at javaapplication7.JavaApplication7.main(JavaApplication7.java:39)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 8 more
Java Result: 1
這些都是我覺得在運行主文件 我所面臨的問題,錯誤的列表
1)我按照正確的方法創建碧玉報告
2)我可以使用xml文件在碧玉報告創建
3)如何創建生成.jrxml文件,並在代碼中使用如碧玉報告模板的格式規範,併爲在那裏我要插入如果我缺少的是,在代碼
4)我也想知道如何碧玉報告與像postgers手動
三江源數據源整合XML設計文件..