• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JasperReports - Desparate Help Required!

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This has been bugging me all day, can anybody offer me some advice how to get started with JasperReports or iReport. Specifically, i need help on setting it up after downloading. When using iReport, it connects with the database fine and creates its report. However, when it comes to compile time it fails. I'm thinking this will have something to do with placing such and such jar file here and setting this variable like this etc. However, after a day searching the net and even buying the online book i just not having any joy.

For example i've tried to create the simple report as detailed here:

web page

I've placed both the java file and jrxml file into the directory C:\Report. When compling the java file i get errors like....cannot find symbol class etc. I've tried all day experimenting with placing various jar files in this Report folder and other things.

I don't really understand the classpath and varible setting bigger picture...this is why i assume this is giving the grief. Any help would be greatly appreciated!! confused:
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm moving this to Other Java API, since the problem seems to be product-specific.
 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've had a mini breakthrough in that i'm now able to create the jrxml file using iReport. If i complie in iReport i get to see the report i have designed and the sql query results just fine in a pdf file. I now want to be able to get generate such a pdf direct from my own java program.

Therefore would/should the following code work?!


As i mentioned in my original post i'm convinced some of my problems arise from my lack of importing the correct jasperreports package. Should i have these import statements?



I would say yes.....however, even if i include these import statements i still get similar error messages. I've put the jasperreports jar file in the same folder that the java source code and jrxml files are located. Is this wrong? If so where should it go?

Some of my complier errors include things like:

package net.sf.jasperreports.engine does not exist
cannot find symbol class JasperReport
etc etc

Any help, ideas or comments would be most welcome. Thank you
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you CLASSPATH does not include the jasperreports.jar file. Make sure that jasperreports.jar and itext.jar and commons-logging.jar are in your classpath... I think that these are the minimum jars needed to export a Jasper report to a PDF.
 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joel,

Thanks for replying, i have studies some of your previous posts on here regaring jasperreports....

Ok, please excuse my complete novice question.....but when we refer to putting something in the classpath does this literally mean in the same folder/place as the java source code? Or does this mean i make an amendment in the environmental variables classpath that points to wherever the jar file in question is? I'm slightly confused on this seemingly simple point!

Thanks for your reply
 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think i'm getting closer but this is still driving me crazy!!! Is my thinking and stages below correct?

Ok, i've created a sucessful report in iReport. Its brilliant, it connects to database, gets my data and looks fab. When i complie in iReport a pdf file loads itself up and i'm in heaven.

I now want to be able to load such a pdf file from my own java application. I now need to use stuff from JasperReports. However, i don't need to create the report design because iReport has done that for me. The iReport created document is in C:\Report and called test.jrxml.

I create the following java program:



I go to complie this code and everything is great. It compiles fine. I think i've cracked it.

I now go to execute the code but get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester at net.sf.jasperreports.engine.JasperManager.loadXmlDesign(JasperManager.java:971) at Jasper.main(Jasper.java:23)

I search the internet for two days and try out various things to do with my classpath relating to the commons-digester-1.7.jar file. This file is located in C:\Program Files\Java\JasperReports\lib. Additionanlly, in my environmental variables i have added it to the path.

Can anybody give a suggestion as to what to try next and stop me going mad?

Thank you for any advice
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

My advice for you is using the file.jasper when you load the report. Go to your iReport folder you will file yourfile.jasper then load it as the following:
JasperReport jasperReport;
JasperPrint jasperPrint;
try {
jasperReport = JasperCompileManager.compileReport(
fileName);
jasperPrint = JasperFillManager.fillReport(
jasperReport, new HashMap(), new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(
jasperPrint, destFileNamePdf);
} catch (JRException e) {
error("Error occured here " + e.toString());
}
However, I am still getting problem with my upper code.when I run this it shows me the error is:
net.sf.jasperreports.engine.JRException: Invalid byte 1 of 1-byte UTF-8 sequence

And I am finding the answer for this.

Could any one in this forum help!

Thanks in advance!

Best regards,

Arthur.
 
Arthur Pham
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did it successfully.
Using the same code but I use Odesign to design to compile the report. But I am still using iReport to design. The step would be:
iReport to design.
Then take the report.jrxml copy it to Odesign and compile it.
It would be ok
Ah, one thing, you have to use the JasperReport of Odesign version to load the report because you must have the same version of JasperReport to compile and to load it.

Good luck.

Arthur.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi master sir I flow your guidance but when I give complied file name that give me error on that line

See my code


Connection conn = null ;
try {
javax.naming.Context ctx = new javax.naming.InitialContext() ;
DataSource ds = (DataSource)ctx.lookup(" java:comp/env/jdbc/Travel" ) ;
conn = ds.getConnection() ;
} catch (Exception ex) {
error(" Error counting rows: " + ex.getMessage() );
}


JasperReport jasperReport;
JasperPrint jasperPrint;



jasperReport = JasperCompileManager.compileReport("c:/fahimjasper/fahim.jasper");


sir what wrong with this code

jasperReport = JasperCompileManager.compileReport("c:/fahimjasper/fahim.jasper");

sir this line give me error


sir please give idea how I create pdf give all remaining step after this error line

thank�s

amir
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Try this,


String FileName = "C:/jasperoutput/employees_report_1.jasper";
String outFileName = "c:/jasperoutput/EmployeeSalary.pdf";
HashMap hm = new HashMap();
try {
//--------------------------PDF-----------------------
JasperPrint print = JasperFillManager.fillReport(FileName, hm,
conn);
JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
outFileName);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.exportReport();
System.out.println("Created file: " + outFileName);


-Rodricks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic