嗨朋友我已經創建了一個java項目,並且還使用該項目中的jasper報告生成報告,當我將我的java項目打包到.exe安裝程序時,jasper報告工作正常,但是當我在另一個系統中部署該exe安裝程序時, jasper報告不起作用ie:jasper報告在我的系統中調用,但不在另一個系統中,我知道我必須更改我的文件路徑,但我不知道如何提供在所有系統和Jasper中接受的文件路徑報告也將在另一個系統中正常工作。賈斯珀報告不工作在Java需要幫助來解決它?
我的代碼是:
try(InputStream is = getClass().getResourceAsStream("C:\\Users\\Applebj\\Documents\\NetBeansProjects\\JavaApplication14\\src\\resources\\bil.jrxml")){
String txt = jLabel1.getText();
String t1=lb2.getText();
String t2=lbl3.getText();
Connection cn;
Class.forName("com.mysql.jdbc.Driver");
cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/billing", "root", "");
Map <String,Object> mp =new HashMap <String,Object>();
mp.put("bj", txt);
mp.put("hpy",t1);
mp.put("li",t2);
// URL urpo=getClass().getResource("/resources/bil.jrxml");
JasperReport jasperReport;
jasperReport = JasperCompileManager.compileReport(is);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,mp, cn);
// JasperExportManager.exportReportToPdfFile(jasperPrint, "C:\\Users\\Applebj\\Desktop\\rep\\simple_report.pdf");
JasperExportManager.exportReportToPdfFile(jasperPrint, "bil.pdf");
JasperViewer.viewReport(jasperPrint);
}
catch(Exception eey){
eey.printStackTrace();
System.out.println(eey.getMessage());
}
好心幫我解決adavance這個問題感謝
我猜測路徑爲'C:\\ Users \\ Applebj \\ Desktop \\ report \\ bil。 jrxml'在其他系統上找不到。您需要以某種方式將'.jrxml'與應用程序捆綁在一起... – MadProgrammer 2014-10-12 05:39:30