aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes JasperReports - Desparate Help Required! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JasperReports - Desparate Help Required!" Watch "JasperReports - Desparate Help Required!" New topic
Author

JasperReports - Desparate Help Required!

Marcus Hathaway
Ranch Hand

Joined: Jun 07, 2005
Posts: 89
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:
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

I'm moving this to Other Java API, since the problem seems to be product-specific.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Marcus Hathaway
Ranch Hand

Joined: Jun 07, 2005
Posts: 89
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
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
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.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Marcus Hathaway
Ranch Hand

Joined: Jun 07, 2005
Posts: 89
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

Joined: Jun 07, 2005
Posts: 89
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
Arthur Pham
Greenhorn

Joined: Oct 04, 2005
Posts: 2
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

Joined: Oct 04, 2005
Posts: 2
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.
muhammad fahim
Ranch Hand

Joined: Dec 17, 2006
Posts: 45
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
Rodricks george
Ranch Hand

Joined: Sep 10, 2006
Posts: 97
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JasperReports - Desparate Help Required!
 
Similar Threads
need to offset a date by intervals of 1 year
difference between JasperReports, iReport, iText and JFreeChart
Problem with jasper report -loading stream
calling jasper reports from java
JasperReports and databases