I am working on integration test case of an action which generate pdf
using jasper
. That jasper have a sub-report
. To get the path of the sub-report (abc.jasper
in web-app/reports/
) I am first fetching real path using
request.getSession().getServletContext().getRealPath("")
which gives /home/mkb/workspace/my-project/web-app
and then concatenating /reports/abc.jasper
to get the sub-report in parent jasper report. This is working fine when running the application (run-app).
But while testing (test-app) above code giving /home/mkb/workspace/my-project/target/work/scriptCache
and hence I am getting
net.sf.jasperreports.engine.JRException: Resource not found at :
/home/mkb/workspace/my-project/target/work/scriptCache/reports/abc.jasper
How can I set or fix this path issue in test cases? (Grails 2.3.9)
Please use ServletContextHolder class static method getRealPath() to get the real path.e.g :-
ServletContextHolder.servletContext.getRealPath('/')
This code will give the path of web-app folder of your application.