简体   繁体   中英

How Can I Change The Location of Image Files Created by BIRT in a Spring Boot Application

I have a Spring Boot application that wraps the Eclipse BIRT reporting tool and runs as a Windows service via winsw. When a report with a chart generated by the engine is rendered, Spring Boot saves the image file in a folder it creates in the Windows/Temp directory. This folder and its contents persist across startups, which is less than desirable.

The application depends on a data folder that exists in a predefined location that exists for all installs of the software package. Given that, the ideal situation would be to create the folders in the package's data folder where it can be managed easily. Is there any way to accomplish this (preferably a method that allows the embedded Tomcat server to find and serve the files)?

Edit: Updated with results of response by @Magnus

The images in question are generated by the ReportEngine render process, so I think it's a BIRT thing not a Tomcat thing, but just to be sure I added server.tomcat.basedir=path/to/directory to my application.properties file. Still writes to Windows/Temp .

However, this reply got me thinking and i found that BIRT's EngineConfig has a setTempFolder method. Setting that to point at the desired folder (with the server.tomcat.basedir value in the properties file) results in BIRT doing work in the temp folder, but the generated images are still saved to the Windows\\Temp directory.

Edit: Update 2

I was able to set the birt.viewer.working.path property in the EngineConfig and confirm that it was set by retrieving the value from the ReportDesignHandle (or maybe the ReportRunnable). With the changed value, the ReportEngine now does its work in the right directory, but still puts images into the Windows\\Temp folder. Overriding the java.io.tmpdir property did nothing.

Edit: Update 3

This kind of works.. Setting the image folder location in the HtmlRenderOption results in the application not creating a folder for generated images in Windows\\Temp (yay!). However, it is not putting the images in the location specified in the HtmlRenderOption, either (boo!), so i'm not really sure where to look so such image files can be cleaned up periodically.

Try to set imageDirectory in HTMLRenderOption.

HTMLRenderOption options = new HTMLRenderOption();
options.setImageDirectory("path/to/image/directory");
...
renderTask.setRenderOption(options);

see http://www.eclipse.org/birt/documentation/integrating/reapi.php

The embedded tomcat defaults to creating a directory in the temp directory specified by the java.io.tmpdir system property.
You can manually set the tomcat temp dir with the application property server.tomcat.basedir

Looking at the codebase there are a few places it deals with creating temp files.
From what I can gather the main place that the temp image directory is set si the ParameterAccessor class.
The logic is fairly complex but, it appears to default to ${birt.viewer.working.path}/report/images .
If the working path system property is not set, or the directory is not writeable then it will default to the java.io.tmpdir directory.
I would try setting the system property birt.viewer.working.path , make sure it is writeable.
If that doesnt work you might have to resort to overriding the java.io.tmpdir system property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM