I'm having a horrible problem and the worst of all is that I can't find almost anything on the web about it! I am making a report in java with jaspersoft studio. I made the template already (it has two parameters) and followed the guide on the next page to the letter .
Ok, my code is the following:
public class Reportes{
private Administrador admin;
public Reportes() throws ClassNotFoundException, SQLException{
admin = new Administrador();
}
public JRViewer obtenerPaciente(String ced) throws JRException{
HashMap parameters = new HashMap();
InputStream is = getClass().getResourceAsStream("assets/PerfilPaciente.jrxml");
JRDesignQuery design = new JRDesignQuery();
design.setText("SELECT * FROM Pacientes");
JasperDesign jd = JRXmlLoader.load(is);
jd.setQuery(design);
parameters.put("Imagen", ClassLoader.getSystemResource("assets/perfil-azul.png").getPath());
parameters.put("Cedula",ced);
JasperReport report = JasperCompileManager.compileReport(jd);
JasperPrint jp = JasperFillManager.fillReport(report, parameters, admin.obtenerConexion());
JRViewer jrv = new JRViewer(jp);
return jrv;
}
}
And when I call that function in my JDialog, it throws me the following error:
net.sf.jasperreports.engine.JRException: java.net.MalformedURLException at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:251) at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML (JRXmlLoader.java:230) at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:218)
I get the following line of code:
InputStream is = getClass().getResourceAsStream("assets/PatientProfile.jrxml");
I have tried to place it "/PerfilPaciente.jrml", "PerfilPaciente.jrxml" and nothing. Nor because it is in the project folder.
How could I solve this?
PS: I place my resources all inside a project folder that I created called "assets", from there some images of my java program also come out, and it has not given me problems like this jrxml file.
Now with what you uploaded I understood better... look there are two ways to do it one is to copy the jrxml in the jar but for that it must be inside the src/assets/PerfilPaciente.jrxml folder and with the code you have it would work.
Since what you are trying to do is that the resource is inside the jar.
Or you could also make this as a resource instead of loading it like this:
Load it as follows, bearing in mind that when you upload the application there will be a folder where your program called assets is executed:
Remember to add the FileInputStream import.
And as cultural data you are using ant.