0

I have a problem with my report on project in NetBeans.

Why is my report cannot viewing while I execute my project.jar but there is no problem while I debug on NetBeans?

Here's the source code

File file = new File("**src/Report/TIKET.jrxml**");// is this the problem?
jasperDesign = JRXmlLoader.load(file);
param.clear();
jasperReport = JasperCompileManager.compileReport(jasperDesign);
jasperPrint = JasperFillManager.fillReport(jasperReport, param,cnn);
JasperViewer.viewReport(jasperPrint, false);
Alex K
  • 22,315
  • 19
  • 108
  • 236
  • I assume that you added the `**` around the filename? But indeed, when the file originally lived in src it's highly doubtful it got included in the final jar (a jar file is a zip file, you can inspect it with any tool you use to manipulate zips. – fvu May 13 '14 at 11:01
  • sorry i just try to bolding src/Report/TIKET.jrxml but i dunno why maybe it's autotext. but actually there is no ** in my project. ok got it thanks I'll try. – user3601846 May 13 '14 at 11:12

1 Answers1

0

The easiest way to ensure your jrxml gets packaged is to handle it as a resource, and load it this way:

jasperDesign = JRXmlLoader.load(TheNameOfYourClass.class.getResourceAsStream("path-to/TIKET.jrxml"));

what path-to should be depends a bit on how you want to structure your project, see eg How to correctly get image from 'Resources' folder in NetBeans where it's proposed to add a resources directory to src, so the final path would be "resources/TIKET.jrxml", but you can also store the jrxml eg in the default package (which represents the root of the package hierarchy).

Community
  • 1
  • 1
fvu
  • 32,488
  • 6
  • 61
  • 79