954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with JasperReports

Hi, I'm using JasperReports in netbeans, on Ubuntu. When I execute my java application on netbeans I have no problem saving the reports, but when I clean and build the program, and run it from the .jar, the program can't save the reports. I don't know if that's because of the folder permissions or the jvm used, please, I need urgent help with this.

Kevingon
Newbie Poster
11 posts since Sep 2011
Reputation Points: 19
Solved Threads: 1
 

Folder permissions are the likely culprit. Is the exception giving you any more information?

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

Actually it doesn't throws any exception, but I use this method to show the report:

try {
                  JOptionPane.showMessageDialog(null,outFileNamePDF);
                  File path = new File (outFileNamePDF);
                  Desktop.getDesktop().open(path);
             }catch (IOException ex) {
                  ex.printStackTrace();
             }


And there's where I get the exception, a file not found one.

Just remember that this works on netbeans, but not when executed from the .jar.

Kevingon
Newbie Poster
11 posts since Sep 2011
Reputation Points: 19
Solved Threads: 1
 

Have you checked the file permission on the location you're showing for 'outFileNamePDF'?

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

What should it be, and where do I check that? I'm kind of a newbie in linux, so tell me what commands should I use on terminal or what should I use on the GUI. Are you talking about the folder permissions? because the file is created from code, with:

pdfExporter.exportReport();

And if the problem is that permission stuff, why netbeans does have permission? this is a portable program, so it must work on any computer. Thanks for the help.

Kevingon
Newbie Poster
11 posts since Sep 2011
Reputation Points: 19
Solved Threads: 1
 

From your code above, it looks like you're showing the file name in a dialog just before opening

JOptionPane.showMessageDialog(null,outFileNamePDF);


Can you check the read/write permissions on that location?

Netbeans created build and dist folders for the files that it generates. I'm not sure how ownership and permissions are set on those. I've never used Ubuntu in my life, so I couldn't tell you how to check them.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

I do show the path before trying to open it, but I don't think that the dist or build folders are the problem as I'm storing the reports in a Report folder, inside the project folder. I made a method to make my program identify if it's running from windows or linux, and if it's running from netbeans or from the .jar, and it's capable of getting the correct path for the reports and my "pseudo-database". The path got inside netbeans, and the path got from the .jar (at executing) are exactly the same, but it only saves the report if it's running inside netbeans, so I doubt it is a permission problem. Thanks

Kevingon
Newbie Poster
11 posts since Sep 2011
Reputation Points: 19
Solved Threads: 1
 

I solved it, it wasn't a permission problem, it was a jar problem. I'll explain:
When netbeans executes the program, it runs from the sources folders, so the report.jasper it's a normal file. When it runs from the .jar, it is inside the jar, and the files inside the jar can't be modified. I think that the jvm can't use the .jasper files inside the jar to make a report.

To solve this just put all the .jasper and other files like images used, inside a .jar, and import it to the project, then change this:

This is how I recovered the .jasper file before:

route = getClass().getResource("/org/almg/report/report1.jasper").getFile();


instead of it just import the jar with the report files to the project, don't use any import in the class and put something like this:

route="/report.jasper";

I just put that because it isn't inside of any folder. That works perfectly for me now. But I'd like someone to explain this better. Thanks for the help Ezzaral.

Kevingon
Newbie Poster
11 posts since Sep 2011
Reputation Points: 19
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: