Search code examples
javaapacheapache-fop

Apache FOP change default cache-file folder


I am attempting to make changes to the config file for Apache FOP (basicFOPConfig.xml) but the changes I make do not seem to make any difference. My end goal is to change the cache file from C:\Users\username.fop\ to C:\ProgramData\programname.fop. Below is the configuration file I am attempting to use.

<fop version='1.0'>
    <cache-file>%programdata%\programname\</cache-file>
    <renderers>
        <renderer mime='application/pdf'>
            <fonts>
                <auto-detect/>
            </fonts>
        </renderer>
    </renderers>
</fop>

As far as I can see, when running the program using Javas ProcessBuilder, it is not throwing any errors/etc. Here is some of the config that might be important.

commandWords = new String[] {
                executable.getAbsolutePath(),
                "-Xms256m",
                "-Xmx" + maxMemory,
                "-jar",
                "fop.jar",
                "-c",
                configFile.getAbsolutePath(),
                "-d",
                "-fo",
                null,
                "-pdf",
                outputFile.getAbsolutePath()
        };

I am not sure if I have missed something important in the setup or configuration. It seems like no matter what I change it seems to ignore the config file and uses the default. I also can't seem to get it to tell me anything about why it is ignoring the config file. If possible I'd like to avoid using the -cache option but may have to use this if the config file does not work.

Any thoughts on this would be helpful, I'll also include a link to Apache's configuration page.

https://xmlgraphics.apache.org/fop/1.0/configuration.html


Solution

  • Eventually I found the cause. Although not explicitly mentioned anywhere, you have to toggle the use-cache flag to make it accept the cache-file tag. Here is an example that worked for my case.

    <fop version='1.0'>
        <use-cache>true</use-cache>
        <cache-file>file:/Directory/fop-fonts.cache</cache-file>
    </fop>