`
flysky
  • 浏览: 65399 次
社区版块
存档分类
最新评论

use japerreports step by step

阅读更多
1.下载japerreports:
网址:https://sourceforge.net/projects/jasperreports/
最好下载完整的zip包:jasperreports-1.3.0-project.zip
这样可以得到所有的文件,包括src,samples。

2.下载到jasperreports-1.3.0-project.zip包后,解压一看,本身是一个project,有.project,.classpath文件等,于是想到可以把它做为一个project导入eclipse中,于是把它拷贝到eclipse的workspace中,然后“import”,即可整个jasperreport工程导入到ecplise了!

注意:我刚开始导入时总出错,提示"Invalid project description",无法导入;后来鬼使神差的把解压后的工程名称"jasperreports-1.3.0"改为"jasperreports"就顺利导入了!
再后来,想把工程改为别的名称,但是import时指定工程根目录后,压根就无反应,"finish"按钮始终是灰色的,无法导入;

最后问了一下wwm,才是知道如果要import a project,则project名称要与.project文件的<name></name>中的名称一致,否则无法导入!
例如,工程名称(根目录)为jasperreports,那么.project中应为:<name>jasperreports</name>;
前面是凑巧改对了。

3.但是导入到eclipse后,它是做为一个java project的,也就方便看源代码而已,到底要怎么才能运行生成报表呢?这就需要ant来执行build.xml。

4.如果没有接触过ant,没关系,很简单的,放心吧。推荐看《java 学习笔记》良葛格 附录A Ant简介(网上搜电子版的即可),15分钟即可搞定ant,不要被它挡路了哦:)

5.并且,eclipse中就自带ant,如果要运行"demo\samples\barbecue"示例,进入"jasperreports\demo\samples\barbecue",右键"build.xml",

选"run as->ant build..",把"javac","compile","fill","view"都打上勾,点"run",ant开始运行该build.xml,不一会,哇,看到报表了!好激动!不过这个报表只有表,没有图,即:看不到自己想要的折线图,柱状图,饼图等。

6.看了一些"demo\samples"下的所有示例,觉得折线图,柱状图,饼图等应该都是在"charts"示例中,意识运行"charts"示例的build.xml文件,但是不能编译通过,提示错误:
javac:
    [javac] Compiling 2 source files to E:\jiangcm\workspace-forict-myeclipse\jasperreports\demo\samples\charts
    [javac] 注意: E:\jiangcm\workspace-forict-myeclipse\jasperreports\demo\samples\charts\ChartsApp.java 使用了未经检查或不安全的操作。
    [javac] 注意: 要了解详细信息,请使用 -Xlint:unchecked 重新编译。
compile:通过,略.
fill:
     [java] java.sql.SQLException: Connection is broken: Connection refused: connect
     [java] at org.hsqldb.Trace.getError(Unknown Source)
     ……
view:
     [java] net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: MultipleAxisChartReport.jrprint

7.怎么办呢?上网查jasper的资料,折腾了大半天,还是没有任何进展,网上的资料都只简单的提到“需要ant”执行,唉,真是没办法。只好转向运行"webapp"示例,运行成功了!(详细看运行jasperreport的webapp示例一文)

8.实在不知道为什么最重要的charts示例无法运行,还是先踏踏实实看一下jasperreports的原理吧,于是认真看了"jasperreports 教程",了解到jasperreports的基本原理:

调用jasperreports的相应的库函数,把.jrxml编译为.jasper;->由.jasper生成.jrprint;->由.jrprint得到各种输出方式的报表。

理解到这一点后,自己就没再往下看,因为能够确定charts示例无法运行绝对与jasperreports的原理无关了。

9.于是,认真分析了一下编译提示的错误,发现主要就是因为编译无法通过造成的,以至于后面缺少对应的.jrprint文件。而编译不通过的原因是“[javac]要了解详细信息,请使用-xlint:unchecked重新编译”,在build.xml中相应位置加上编译参数:
<javac srcdir="src" destdir="${classdir}">
<compilerarg value="-Xlint:unchecked"/>

终于编译通过了!!(详细参见“Eclipse中报错"要了解详细信息,请使用-xlint unchecked重新编译"的解决方案”一文)

10.这时javac通过了,即ChartsApp.java编译通过了,但是fill和view这两步还是提示原来的错误,如下所示:
javac:
    [javac] Compiling 2 source files to E:\jiangcm\workspace-forict-myeclipse\jasperreports-1.3.0-project\demo\samples\charts
    [javac] E:\jiangcm\workspace-forict-myeclipse\jasperreports-1.3.0-project\demo\samples\charts\ChartsApp.java:115: 警告:

[unchecked] 对作为普通类型 java.util.Map 的成员的 put(K,V) 的调用未经检查
    [javac] parameters.put("MaxOrderID", new Integer(12500));
    [javac] ^
    [javac] 1 警告
compile:
fill:
     [java] java.sql.SQLException: Connection is broken: Connection refused: connect
     [java] at org.hsqldb.Trace.getError(Unknown Source)
view:
     [java] net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: MultipleAxisChartReport.jrprint
     [java] at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:75)
其中fill这一步提示的是SQLException的错误,难道是要配置数据源或者是要运行什么东西?
再看fill的出错提示:"[java] at org.hsqldb.Trace.getError(Unknown Source)",对了,好像"demo"文件夹里有"hsqldb"文件夹,是不是要先运行"hsqldb"文件夹的内容??试试。

10.于是ant编译"demo\hsqldb"的build.xml;提示:server is running...
应该是数据库启动了;

11.接着ant编译"demo\samples\charts"的build.xml;顺利fill,耶!看到曲线图、柱状图等报表了!

12.备注:关掉报表再直接运行一次charts的build.xml,还能正确看到报表;关掉eclipse再运行,也也还能正确看到报表;看来hsqldb只要运行过一次,以后就都有效了!至于原理就不太明白了,难道是hsqldb运行过之后就永久的把数据导入到工程的报表中了?有待以后学习验证了。

13.小结:
运行jasperreports示例,关键是要注意和解决三个问题:
1)import project时,工程名称要与.project文件中"<name></name>"中的名称一致,否则无法导入;

2)jdk版本兼容的问题:
加入编译参数:<compilerarg value="-Xlint:unchecked"/>

3)要先运行一下"demo\hsqldb"下的build.xml,启动数据库导入数据,才能fill报表,运行显示报表;
ok!

以上步骤重复验证过两三次均无问题,按上述步骤保证就能运行jasperreports提供的charts关键示例了!

ok!



分享到:
评论
2 楼 flysky 2007-01-25  
抱歉哦,我这两天刚刚开始接触jasperreports,刚能把它跑起来,还不会分页。
1 楼 southgate 2007-01-25  
如何换页,或者控制每页行数
英雄是否知晓?

相关推荐

    How to use OpenCV step by step in VC

    ### 如何在Visual C++ 6.0上逐步使用OpenCV #### 第一步:使用Visual C++ 读入文件 1. **启动 Visual C++**:打开Visual C++ 6.0开发环境。 2. **创建新项目**:选择“文件”&gt;“新建”,在弹出的新建项目窗口中...

    Microsoft ADO.NET Step by Step

    Microsoft ADO .NET Step by Step ISBN: 0735612366 by Rebecca M. Riordan Microsoft Press ? 2002 (512 pages) Learn to use the ADO.NET model to expand on data-bound Windows and ...

    Microsoft Visual C++/CLI Step by Step Aug 2013 PDF ePub

    Microsoft Visual C++/CLI Step by Step (pdf + ePub) Publisher: Microsoft Press (August 2, 2013) Language: English ISBN-10: 0735675171 ISBN-13: 978-0735675179 Your hands-on guide to Visual C++/CLI ...

    Microsoft - Microsoft Visual Basic 2010 Step by Step May 2010

    Microsoft Visual Basic 2010 Step by Step 576 pages Publisher: Microsoft Press; 1 edition (May 7, 2010) Language: English ISBN-10: 0735626693 ISBN-13: 978-0735626690 Your hands-on, step-by-...

    Drupal 8 Explained: Your Step-by-Step Guide to Drupal 8

    Drupal 8 Explained: Your Step-by-Step Guide to Drupal 8 (The Explained Series) by Stephen Burge English | 3 Apr. 2017 | ASIN: B06Y1VN2D7 | 283 Pages | AZW3 | 13.66 MB We're delighted to present the ...

    Microsoft.Project.2016.Step.by.Step.073569874

    Jump in wherever you need answers–brisk lessons and colorful screenshots show you exactly what to do, step by step. Quickly start a new plan, build task lists, and assign resources Share your plan ...

    Microsoft Visual C# 2010 Step by Step Mar 2010

    Ideal for developers with fundamental programming skills, this practical tutorial features learn-by-doing exercises that demonstrate how, when, and why to use the features of the C# rapid application...

    Microsoft SQL Server2005 Analysis Step by Step

    Teach yourself the fundamentals of SQL Server Analysis Services—one step at a time. With this practical, learn-by-doing tutorial, you get the guidance you need to build flexible and powerful ...

    Microsoft PowerPoint 2016 Step by Step

    Microsoft Point Power - You can use PowerPoint 2016 to develop professional presentations for electronic delivery as on-screen slide shows, or for print delivery as slide decks with handouts and note ...

    Microsoft Visual C# 2010 Step by Step

    Microsoft Visual C# 2010 Step by Step Microsoft Press This book assumes that you are a developer who wants to learn the fundamentals of ­programming with C# by using Visual Studio 2010 and the .NET ...

    SAP BW - A Step-By-Step Guide.chm

    SAP® BW: A Step-by-Step Guide By Biao Fu, Henry Fu Publisher : Addison Wesley Pub Date : July 23, 2002 ISBN : 0-201-70366-1 Pages : 480 SAP BW has recently come to the fore as a valuable ...

    idoc上传Step-by-step guide on File-to-IDoc using SAP PI 7.0

    In conclusion, this step-by-step guide outlines the process of implementing a one-way asynchronous File-to-IDoc scenario in SAP PI 7.0. By following these steps, you can efficiently transfer supplier ...

    Microsoft ADO.NET 4 Step by Step

    Book Description Teach yourself the fundamentals of ADO...Your step by step digital content includes: Practice exercises Fully searchable online edition of this book — with unlimited access on the Web

    C.Programming.Step.By.Step.Beginners.To.Experts.Edition.B011EXMV7Q

    This book is the fastest way to get comfortable with C, one incredibly clear and easy step at a time. You’ll learn all the basics: how to organize programs, store and display data, work with ...

    layui-步骤条step-源码-导入即用

    layui.use(['step'], function(){ var step = layui.step; // 在这里编写你的代码 }); ``` 在这个例子中,`'step'`是layui步骤条组件的模块名,加载后可以通过`layui.step`来调用相关方法和配置。具体使用时,你...

    Microsoft Project 2013 Step by Step

    1. 书名《Microsoft Project 2013 Step by Step》指向了这是一本教授Microsoft Project 2013使用方法的书籍,重点在于逐步指导学习,适合初学者按照步骤自我学习。 2. 描述中提到的“create and fine-tune your ...

Global site tag (gtag.js) - Google Analytics