当我在 Netbeans 中运行它时它工作正常,但它不会显示在可执行 jar 文件中这是我的代码
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
rep.siapkan_report_dengan_parameter("report4.jrxml", "Report", "periode",tCari.getText());
this.setCursor(Cursor.getDefaultCursor());
}
public void siapkan_report_dengan_parameter(
String nama_report,
String direktori,
String namaparameter,
String isiparameter){
konek.openConnection();
Properties systemProp = System.getProperties();
// Ambil current dir
String currentDir = systemProp.getProperty("user.dir");
File dir = new File(currentDir);
String reportName = nama_report;
String reportDirName = direktori;
File fileRpt;
String fullPath = "";
if (dir.isDirectory()) {
String[] isiDir = dir.list();
for (int i = 0; i < isiDir.length; i++) {
fileRpt = new File(currentDir + File.separatorChar + isiDir[i] + File.separatorChar +
reportDirName + File.separatorChar + reportName);
if (fileRpt.isFile()) { // Cek apakah file ada
fullPath = fileRpt.toString();
}
}
}
String[] subRptDir = fullPath.split(reportName);
try {
// Persiapkan parameter untuk Report
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put(namaparameter, isiparameter);
try {
JasperReport JRpt = JasperCompileManager.compileReport(fullPath);
JasperPrint JPrint = JasperFillManager.fillReport(JRpt, parameters,konek.conn);
if(JPrint.getPages().isEmpty()){
JOptionPane.showMessageDialog(null,
"Data Untuk Kriteria :\n" + isiparameter +"\nTidak Ada",
"Peringatan",
JOptionPane.ERROR_MESSAGE);
}else{
JasperViewer.viewReport(JPrint, false);
}
} catch (Exception rptexcpt) {
JOptionPane.showMessageDialog(null,
"a",
"Peringatan",
JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,
"b",
"Peringatan",
JOptionPane.ERROR_MESSAGE);
}
}
提前致谢!
我的图书馆是:
- common-beanutils-1.7
- commons-collections-2.1
- commons-digester-1.7
- commons-javaflow-20060411
- 公共日志记录-1.1
- jasperreports-3.0.1
- jdt-compiler-3.1.1
- jfreechart-1.0.3
- poi-3.0.1-FINAL-20070705