I have a java project with a jasper report. The report works perfectly fine in eclipse but is not showing in the jar file. In the folder that has the report I have a folder with my database and my .jasper file.
this is how it looks like :
And this is how my database folder looks like :
And this is how my code for the report looks like :
public JFrame compileReport(String city, int capacity) {
String path = getPath();
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
try (Connection conn = DriverManager.getConnection(Consts.CONN_STR)) {
HashMap<String, Object> params = new HashMap<>();
params.put("p1", city);
params.put("capacity", capacity);
JasperPrint print = JasperFillManager.fillReport(path,params, conn);
JFrame frame = new JFrame("Docking Stations Ordered By Country");
frame.getContentPane().add(new JRViewer(print));
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.pack();
return frame;
} catch (SQLException | JRException | NullPointerException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
private static String getPath() {
try {
String path = Consts.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decoded = URLDecoder.decode(path, "UTF-8");
if (decoded.contains(".jar")) {
decoded = decoded.substring(0, decoded.lastIndexOf('/'));
return decoded + "/database/Report.jasper";
}
else {
decoded = decoded.substring(0, decoded.lastIndexOf("bin/"));
return decoded + "src/Boundary/Report.jasper";
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
I can't unserdstand why my report isn't showing up in the jar file.