File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes Jasper Report and JAR file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Jasper Report and JAR file" Watch "Jasper Report and JAR file" New topic

Jasper Report and JAR file

Talhah Mafawalla

Joined: Nov 05, 2006
Posts: 24
Hi to all,

I am having a problem that i have been working on for about a week now. I a have just started using jasper reports.

The problem is that when i am runing my application in Netbeans 5.5 IDE i have no problems providing the path to the .jrxml file which is

Though when the application is complied into a jar file with the .jrxml file inside the jar file aswell, i get the following error:

I have tried to give the path dynamically using the following code:

but I also get an error. I would like to know how to give a reference to a .jrxml file located inside a jar file.

Tanks in advance.

Talhah Mafawalla
dennis zined
Ranch Hand

Joined: Mar 07, 2003
Posts: 330
if its compiled and packaged into a jar file your code should be pointing to the compiled report file (*.jasper) and not the raw version (*.jrxml).

hope this helps.

SCJP 1.4<br />SCWCD 1.4
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Provide the absolute path within the jar file, not a path that's relative to something. For example if the "reports" directory is in the root of the jar file, then like this:And don't do getPath() after that. You can't get a File object from a jar file, so if you planned to pass a File to some method, try again. Find the version of the method that accepts an InputStream instead and call getResourceAsStream() instead of getResource().
Talhah Mafawalla

Joined: Nov 05, 2006
Posts: 24
Thanks Dennis and Paul,

I have found the solution to this problem by using the method suggested by Dennis, I have found that the JasperFillManager class has a method ".fillReport()" that excepts and InputStream as a paremeter, and I am happy to say that i have the report generated.

Thanks again for your input.

Talhah Mafawalla.
rama krishnan
Ranch Hand

Joined: Mar 14, 2008
Posts: 68
In which way the Jasper Report Tool is working in Java?
Is there any methods?

prabhu ganapathylingam

Joined: Oct 15, 2010
Posts: 8

I am using the following code

con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dgimageapp","root","ikure");
//Getting the xml file
InputStream in =getClass().getResourceAsStream("reports/report1.jrxml");

JasperDesign jasperDesign = JRXmlLoader.load(in);

//Build a new query
query = "select pid,fname,lname,mobileno from dg_patient where date between '"+from+"' and '"+to+"'";

// update the data query
JRDesignQuery newQuery = new JRDesignQuery();

//compiling and creating the report
//JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

//filling the Report and add it to
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, con);

// JasperViewer.viewReport(jasperPrint);
JRViewer viewer1=new JRViewer(jasperPrint);
JFrame jf=new JFrame();

catch (JRException e)
catch (SQLException e)

while i am running the code in netbeans IDE. it will show the report.
but when i am trying to run a jar, the report is not coming

help me

thanks in advance
marko zorko

Joined: Dec 02, 2010
Posts: 1
I'm developing app in Rational and this method is working locally... Creates pdf and everything... But when I compile my app and create jar with .jasper files and try to run my app over .bat it's not woriking anymore... like .jasper file is not found...

My method:
public void writePdfFile(List<MyObject> data, Map<String,Object> map, String FilePathAndNAme) throws IOException, JRException{

InputStream is = getClass().getResourceAsStream("reports/my_name.jasper"); //like in my jar

String fileType = ".pdf";
String outFileName = FilePathAndNAme+this.yearmm+ fileType;
JRDataSource dataSource = new JRBeanCollectionDataSource(data);

JasperPrint jasperPrint = JasperFillManager.fillReport(is, map, dataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, outFileName);
catch (JRException jre){
catch (Exception e){

net.sf.jasperreports.engine.JRException: file:\C:\myJar.jar!\reports\my_name.jasper
at net.sf.jasperreports.engine.util.JRLoader.loadObject(
at net.sf.jasperreports.engine.JasperFillManager.fillReport(
at net.sf.jasperreports.engine.JasperRunManager.runReportToPdfFile(
at si.triglav.batch.porocilaKnjigovodstvo.myClass.writePdfFile(
at si.triglav.batch.porocilaKnjigovodstvo.myClass.executeBatch(
at si.triglav.batch.BatchRoot.initialization(
at si.triglav.batch.porocilaKnjigovodstvo.myClass.main(
Caused by: file:\C:\myJar.jar!\reports\my_name.jasper
... 7 more
Andrej Nadilo

Joined: Nov 11, 2011
Posts: 1
Hi to all,

I have the same problem as Talhah:

When running my application through IDE, the report generates without any problems - I am able to view it through JasperViewer, print it and everything seems to work fine.

However, when application is deployed to Jar the report doesn't get generated. All needed Jasper libraries are included in the Jar. The .jasper file is located inside the Jar but I have the same problem no matter where I locate it.

I tried starting the Jar through Command Prompt and got an error thrown while generating the report: Stream closed .....

The code for generating the report is below.

I tried so many different things and nothing seems to work. What do you think the problem is? Please HELP

Code that generates a report:

I agree. Here's the link:
subject: Jasper Report and JAR file
It's not a secret anymore!