Proper Jasperreports setup - how?

2

 

Hi, for last 2 days i'm trying to get jasperreports to work.

I'm trying to create simple Java SE application. All the tutorials i found cover the jasper xml files, editing the report etc. I'm stuck being unable to find anything about how to properly configure jasperreports library and it's dependencies. 

Is there a tutorial somewhere how to set this up? All i find is:

A) How to edit report xml

B) How to edit report.xml with iReports

 

To setup project in Eclipse i tried:

1) i added jasperreports-5.0.0.jar to buildpath, along with jasperreports-javaflow-5.0.0.jar, applet, and fonts (should I add those files too? If they are integral parts why are the jars separate?)

2) i added dependancies to buildpath:

commons-beanutils-1.8.3.jar

commons-collections-3.2.1.jar

commons-digester-1.7.jar (that was a pain to get. Apache Commons Digester site goes 403 Forbidden on Download page)

commons-logging-1.1.1.jar

itextpdf-5.4.0.jar

itext-pdfa-5.4.0.jar

itext-xtra-5.4.0.jar

3) i created test application

public static void main(String [] args) {
JasperReport jasperReport;
JasperPrint jasperPrint;

try {
jasperReport = JasperCompileManager.compileReport("hw.xml");
jasperPrint = JasperFillManager.fillReport(jasperReport,
new HashMap(), new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(jasperPrint,
"reports/simple_report.pdf");
} catch (JRException e) {
e.printStackTrace();
}}

the hw.xml file:

--removed because it broke the post formatting --

result:

 

Feb 27, 2013 11:45:52 AM net.sf.jasperreports.engine.component.ComponentsEnvironment findBundles
WARNING: Found two components for namespace http://jasperreports.sourceforge.net/jasperreports/components
Feb 27, 2013 11:45:52 AM net.sf.jasperreports.engine.component.ComponentsEnvironment findBundles
WARNING: Found two components for namespace http://jasperreports.sourceforge.net/jasperreports/components
Feb 27, 2013 11:45:53 AM net.sf.jasperreports.engine.component.ComponentsEnvironment findBundles
WARNING: Found two components for namespace http://jasperreports.sourceforge.net/jasperreports/components
Feb 27, 2013 11:45:53 AM net.sf.jasperreports.engine.xml.JRBandFactory createObject
WARNING: The 'isSplitAllowed' attribute is deprecated. Use the 'splitType' attribute instead.
Exception in thread "main" java.lang.NoClassDefFoundError: com/lowagie/text/DocumentException
at net.sf.jasperreports.engine.JasperExportManager.exportToPdfFile(JasperExportManager.java:145)
at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(JasperExportManager.java:497)
at Test.main(Test.java:21)
Caused by: java.lang.ClassNotFoundException: com.lowagie.text.DocumentException
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 3 more

pawel.kosciuk's picture
Joined: Feb 25 2013 - 4:21am
Last seen: 2 years 5 months ago

1 Answer:

0

There is a very good full sample in the library download (download jasperreports-5.0.0-project.zip from http://community.jaspersoft.com/project/jasperreports-library/releases) and go to /jasperreports-5.0.0/demo/samples/webapp.

That web application goes over the full lifecycle of a report from compilink the JRXML to exporting a PDF or other formats.

Also check the tutorial here: http://community.jaspersoft.com/wiki/jasperreports-library-tutorial and you can find more resources and information here: http://community.jaspersoft.com/project/jasperreports-library/resources

marianol's picture
4427
Joined: Sep 13 2011 - 8:04am
Last seen: 9 months 2 weeks ago

Thank you for your answer.

As i stated, i don't have trouble with creating Jasper xmls, or using JAsper library in my app code. I had trouble with setting up all JAsperReports dependencies. I work-arounded that by including every .jar in lib folder from jasperreports-5.0.0-project, but that does not solve the base issue which is lack of proper list of required libraries with links to download compatible versions of those libraries. The page here:
http://community.jaspersoft.com/wiki/jasperreports-library-requirements
didn't help because current iText releases are apparently incompatible with current JasperReports, amd commons-digester download page is not working.

Right now i include all libs from jasperreports-5.0.0-project, including some that look like they are JSP/JavaEE stuff, making it 40MB of dependancies.

Anyway, thanks for your help, I'll just have to remove libraries one by one and check if it breaks JasperReports.

pawel.kosciuk - 6 years 4 months ago

Im using this code and im getting the error below:
try{

try{
JasperDesign jps = JRXmlLoader.load("ReporteComprasPF.jrxml");
String sql = "select * from compras where fecha_c ='"+((JTextField)fdesde.getDateEditor().getUiComponent()).getText()+"'";
JRDesignQuery newquery = new JRDesignQuery();
newquery.setText(sql);
jps.setQuery(newquery);
JasperReport jsp = JasperCompileManager.compileReport(jps);
JasperPrint jspp = JasperFillManager.fillReport (jsp,null,con);
JasperViewer.viewReport(jspp);
} catch (Exception ex){
JOptionPane.showMessageDialog(null, ex);
}
}catch (NumberFormatException efn){
JOptionPane.showMessageDialog(rootPane, efn);
}

may 25, 2013 2:30:43 PM net.sf.jasperreports.engine.component.ComponentsEnvironment findComponentBundles
WARNING: Found two components for namespace http://jasperreports.sourceforge.net/jasperreports/components
may 25, 2013 2:30:43 PM net.sf.jasperreports.engine.component.ComponentsEnvironment findComponentBundles
WARNING: Found two components for namespace http://jasperreports.sourceforge.net/jasperreports/components

ing.elvisrodriguez - 6 years 1 month ago
Feedback
randomness