2014-10-28 42 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

相關問題