views:

35

answers:

1

I'm using netBeans and I'm trying to generate a report unsing Jasper Report
Can I get the url (of the local jrxml file) of the report which is stored in the the following directory structure

My_project
   |_build
   |_dist
   |_nbproject
   |_src
     |_my_project
     |_META_INF
     |_report.jrxml
     |_report.jasper

I dont want to add the absolute path to my report file I want java /java classes to do that for me is there any way to get the file name parameter in

JasperDesign jasperDesign = JRXmlLoader.load ("__MY_REPORT_NAME");
+1  A: 

You can use :

InputStream in = 
      getClass().getResourceAsStream("/relative/path/to/yourReport.jasper");
JasperDesign jasperDesign = JRXmlLoader.load(in);
Bozho
actually I want my app to ge the relative url of the file (when I'm using netbeans and when I'm deploying it as a jar file)
charanraj
I'm sorry If I've not placed my questions correctly
charanraj
@charanraj it should be in the same location in both cases - relative to the classpath. Otherwise you have an environment issue.
Bozho
I'm not getting it :'(
charanraj
thanks for the answer.I'll try to figure it out :( your answer surely is a great help to me.Thanks for showing concern and answering my question
charanraj
relative path to classpath root means that it does not depend on where your jar/bin folders are - you are location resources relative to the jar root, or the the bin folder
Bozho
hey Mr Bozho .thanks I got my answer+ it helped in solving my problem .Thanks a lot :)
charanraj