Reputation: 790
I have a problem, I used iReport in making a report for my inventory system. Everything seems to be working fine until i tested it after building an executable file. when i press the button nothing happens.
here is the code for my button.
The report shows up when i run the file on netbeans but not in the executable file. what might be causing the problem.
try {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + Connect.URL();
conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
JasperDesign jasperDesign = JRXmlLoader.load("report1.jrxml");
String sql = "select * from Incoming";
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(sql);
jasperDesign.setQuery(newQuery);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
JasperViewer.viewReport(jasperPrint);
} catch (SQLException | JRException ex) {
Logger.getLogger(Inventory_ReportFrm.class.getName()).log(Level.SEVERE, null, ex);
}
Upvotes: 0
Views: 2709
Reputation: 1
Just copy your .jrxml file into dist folder it will work properly
Upvotes: 0
Reputation: 88
Add your jrxml file which is to be loaded to your class path. Use the compile mananger to compile the report and save to a absolute location. Better use C documents as the absolute location.
String documents=newJFileChooser().getFileSystemView().getDefaultDirectory().toString();
JasperCompileManager.compileReportToFile(jasperDesign,documents+"\\report1.jasper");
JasperPrint jasperPrint = JasperFillManager.fillReport(documents+"\\report1.jasper, null, conn);
JasperViewer.viewReport(jasperPrint,false);
Upvotes: 1
Reputation: 790
I've made a solution to this problem about iReport/jasper report not opening/running upon making an executable.
Seems that the program (executable) cannot locate the .jrxml/.jasper file in its default location (within the project folder usually with the build and manifest file) so the alternative would be to save the report file somewhere in the hard disk. ex. "D:/Files and Documents/Documents/report1.jrxml"
This works but somehow not the proper way. Most programmers would want to do this using a relative path. if the file you're linking to is in the same directory. However i cant figure out why it doesn't work on an executable. so i decided to use an absolute path which would be a problem if i decided to use this on another computer.
anyway it works. :)
Upvotes: 0