2016-10-12 35 views
0

如何在處理器vs編輯器中處理圖像路徑不同的jasper報告?Jasper在編輯器和運行時報告圖像引用

下面是一個例子:

我在文件夾/src/main/resources/reporttemplates/MyReport.jrxml

報告定義該報告包括位於/ src目錄/主/資源的圖像/ reporttemplates /圖片/ MyImage.png

當它似乎接受兩個不同的路徑類型的編輯器指的是圖像:

無論是絕對項目路徑:「/ src目錄/主/資源/ reporttemplates /圖片/ MyImage.png「或或基於報告定義目錄的相對路徑:「images/MyImage.png」

但是,在運行時,路徑需要更改。在我的情況下,當項目構建並部署到Tomcat時,映像的路徑需要與Web應用程序的classes文件夾相關:「reporttemplates/images/MyImage.png」。

任何技巧,使這項工作?

回答

0

找到很好的解決了這個問題:

當指定圖像的路徑,我可以使用:$P{image_path} + "/MyImage.png"

然後,所有我需要做的是設置IMAGE_PATH,在編輯工作的默認值(例如「/ src/main/resources/reporttemplates/images」)。最後,當從Web應用運行報告時,我可以在運行時指定不同的路徑(例如「reporttemplates/images」)。

來源: http://www.oodlestechnologies.com/blogs/Using-Jasper-Reports-Part-5--(Adding--dynamic-path-to-images-in-jasper)