2014-10-28 44 views
0

我正在使用jasper生成pdf动作的集成测试用例。那碧玉有sub-report。为了让子报告(在web-app/reports/abc.jasper)的路径,我先取出使用spock集成测试用例中的应用程序实际路径问题

request.getSession().getServletContext().getRealPath("") 

这给/home/mkb/workspace/my-project/web-app然后连接/reports/abc.jasper得到父碧玉报告的子报告真实路径。这在运行应用程序(run-app)时工作正常。

不过,虽然测试(测试应用程序)上面的代码给/home/mkb/workspace/my-project/target/work/scriptCache,因此我得到

net.sf.jasperreports.engine.JRException: Resource not found at : 
/home/mkb/workspace/my-project/target/work/scriptCache/reports/abc.jasper 

如何设置或测试的情况下解决这个问题的路径?(Grails的2.3.9)

回答

2

请使用ServletContextHolder类的静态方法getRealPath(),以获得真正的path.eg: -

ServletContextHolder.servletContext.getRealPath('/') 

这个代码将会给你的应用程序的Web的应用程序文件夹的路径。

+0

工作真棒。谢谢 – user1690588 2014-10-28 10:20:11

相关问题