Results 1 to 6 of 6

Thread: JasperReport: Is it possible to access *.japser file outside project directory?

  1. #1

    Question JasperReport: Is it possible to access *.japser file outside project directory?

    Our project want to locate the compiled *.jasper file outside project direcotry, e.g. put the *.jasper file under /home/jars/reports/testReport.jasper (in liunx server machine) and make the project can access this *.jasper file directly.

    (We do not want to put it inside project directory (i.e. /WEB-INF/report/...), Since the server need to restart for each report modification in order to put the latest *.jasper into the WAR.)

    But, is it possible for Spring+JaserReport project to access the *.jasper file located on the disk other than the project directory??

    I have tried put *.jasper under:
    (views.properties)
    Code:
    report.url=/home/jars/reports/testReport.jasper
    in my linux machine, it does not work, Only when I put the file inside project direcotry:
    Code:
    report.url=/WEB-INF/reports/testReport.jasper
    , it works.

    So, is it possible for Spring+JasperReport project access *.jasper file outside the project directory???
    Last edited by mellon; Apr 12th, 2009 at 04:51 AM.

  2. #2

    Default AbstractJasperReportsView

    I looked briefly into this, and this is what I found. AbstractJasperReportsView uses a call of
    Code:
    	protected JasperReport loadReport() {
    		String url = getUrl();
    		if (url == null) {
    			return null;
    		}
    		Resource mainReport = getApplicationContext().getResource(url);
    		return loadReport(mainReport);
    	}
    From ResourceLoader (ApplicationContext implements it)
    Code:
    Return a Resource handle for the specified resource. The handle should
    always be a reusable resource descriptor, allowing for multiple
    InputStreamSource.getInputStream() calls.
    
    • Must support fully qualified URLs, e.g. "file:C:/test.dat".
    • Must support classpath pseudo-URLs, e.g. "classpath:test.dat".
    • Should support relative file paths, e.g. "WEB-INF/test.dat". (This will be implementation-specific, typically provided by an ApplicationContext implementation.)
    So I'd try the file:/path/to/file to see if that does it.

  3. #3

    Unhappy

    Quote Originally Posted by pbdavey View Post
    I looked briefly into this, and this is what I found. AbstractJasperReportsView uses a call of
    Code:
    	protected JasperReport loadReport() {
    		String url = getUrl();
    		if (url == null) {
    			return null;
    		}
    		Resource mainReport = getApplicationContext().getResource(url);
    		return loadReport(mainReport);
    	}
    From ResourceLoader (ApplicationContext implements it)
    Code:
    Return a Resource handle for the specified resource. The handle should
    always be a reusable resource descriptor, allowing for multiple
    InputStreamSource.getInputStream() calls.
    
    • Must support fully qualified URLs, e.g. "file:C:/test.dat".
    • Must support classpath pseudo-URLs, e.g. "classpath:test.dat".
    • Should support relative file paths, e.g. "WEB-INF/test.dat". (This will be implementation-specific, typically provided by an ApplicationContext implementation.)
    So I'd try the file:/path/to/file to see if that does it.
    So, what is the result? is it working when you put the *.jasper file on local disk other than project direcotry??

    Anyother suggestions are appreciated...

  4. #4

    Default

    I looked into it and made a suggestion, leaving it up to you to verify the validity of it. I gave supporting evidence that it *MAY* work. I don't have time to test the hypothesis also.

  5. #5

    Question

    Quote Originally Posted by pbdavey View Post
    I looked briefly into this, and this is what I found. AbstractJasperReportsView uses a call of
    Code:
    	protected JasperReport loadReport() {
    		String url = getUrl();
    		if (url == null) {
    			return null;
    		}
    		Resource mainReport = getApplicationContext().getResource(url);
    		return loadReport(mainReport);
    	}
    From ResourceLoader (ApplicationContext implements it)
    Code:
    Return a Resource handle for the specified resource. The handle should
    always be a reusable resource descriptor, allowing for multiple
    InputStreamSource.getInputStream() calls.
    
    • Must support fully qualified URLs, e.g. "file:C:/test.dat".
    • Must support classpath pseudo-URLs, e.g. "classpath:test.dat".
    • Should support relative file paths, e.g. "WEB-INF/test.dat". (This will be implementation-specific, typically provided by an ApplicationContext implementation.)
    So I'd try the file:/path/to/file to see if that does it.
    Hi, I have some questions about your suggestion:
    1. In your code
    Code:
    String url = getUrl();
    , is this url get from view.properties file? E.g. if inside views.properties I have a definition: report.url=/home/jar/report/myReport.jarsper, will your code get url="/home/jar/report/myReport.jarsper"??

    2. Since I use Spring+JasperReport, normally, I use controller to return the ModelAndView("dataSrouce",dataSource), and this modelAndView will go to views.properties to find the right url and display the report.

    But, in your code, you return a JasperReport type object, what should my controller do with this object to display report??

    3. About the ResourceLoader, how to implement it in ApplicationContext, any sample code is appreciated.

    I will look forward to hear you , thank you And anyother suggestions are appreciated.

  6. #6

    Default

    The code that returns a report is not my code. It is code from one of the base classes in the JasperReportsView hierarchy. I'm not suggesting you change any of your Controller code. It would all be in the configuration of the view.

    In your properties file for the resource bundle config:
    Code:
    report.url=file:/home/jar/report/myReport.jasper
    Since your code worked with the jasper in your WAR, I think it's just that line that needs to change along with relocating the jasper to the directory.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •