Search code examples
javamavenapache-fop

Apache FOP/Xmlgraphics can't load SVG if it is in a jar


I've got an application using Apache FOP to create a PDF which includes an SVG image (it's a logo and is the same every time) I find that it doesn't include the image if I use Maven's assembly plugin to create a jar-with-dependencies. I did some work to narrow it down and it seems that the SVG image loader isn't registered when the application is in a jar - so it's not the PDF part of FOP as such, it's the ImageManager which is in xmlgraphics-commons.

I've pasted in a minimal example below, it will need files called img.png, img.tiff and img.svg in the current directory.

If you run this with mvn exec:java it prints out

image (image/png)
image (image/tiff)
image (image/svg+xml)

and if you run mvn package and then java -cp .\target\mavenproject2-1.0-SNAPSHOT-jar-with-dependencies.jar project.Mavenproject2 you get

image (image/png)
image (image/tiff)
Nov 26, 2024 10:19:15 AM project.Mavenproject2 load
SEVERE: Loading img.svg
org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for image
        at org.apache.xmlgraphics.image.loader.ImageManager.preloadImage(ImageManager.java:181)
        at project.Mavenproject2.load(Mavenproject2.java:43)
        at project.Mavenproject2.main(Mavenproject2.java:31)

null

So the SVG loader is not available.

Is there a way to tell FOP to register that SVG loader or it impossible to run it from a jar with dependencies and I should look to package the application some other way?

Minimal example code:

package project;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import org.apache.fop.apps.FopFactoryBuilder;
import org.apache.xmlgraphics.image.loader.ImageException;
import org.apache.xmlgraphics.image.loader.ImageInfo;
import org.apache.xmlgraphics.image.loader.ImageManager;
import org.apache.xmlgraphics.image.loader.ImageSource;

public class Mavenproject2 {

    public static void main(String[] args) throws FileNotFoundException, ImageException, IOException {
        Mavenproject2 me = new Mavenproject2();
        System.out.println(me.load("img.png"));
        System.out.println(me.load("img.tiff"));
        System.out.println(me.load("img.svg"));
    }

    public Mavenproject2() {
        URI base = URI.create("https://example.com/nowhere");
        FopFactoryBuilder ffb = new FopFactoryBuilder(base);
        this.imageManager = ffb.getImageManager();
    }
    private final ImageManager imageManager;

    public ImageInfo load(String ff) {
        try {
            File sourceFile = new File(ff);
            ImageInputStream iis = ImageIO.createImageInputStream(sourceFile);
            ImageInfo preloadImage = imageManager.preloadImage("image", new ImageSource(iis, "image", true));
            return preloadImage;
        } catch (IOException | ImageException ex) {
            Logger.getLogger(Mavenproject2.class.getName()).log(Level.SEVERE, "Loading " + ff, ex);
        }
        return null;
    }
}

and the POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>project</groupId>
    <artifactId>mavenproject2</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>fop</artifactId>
            <version>2.10</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.release>21</maven.compiler.release>
        <exec.mainClass>project.Mavenproject2</exec.mainClass>
    </properties>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.7.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptorRefs>
                                jar-with-dependencies
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Using maven 3.9.9 on Windows11.

[edit] Logging as requested by @francesco-poli When not in a jar (and it works)

Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderTIFF with priority 1000
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderGIF with priority 1000
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderJPEG with priority 1000
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderBMP with priority 1000
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderEMF with priority 1000
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderEPS with priority 1000
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.PreloaderImageIO with priority 2000
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderRawPNG with priority 2000
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.fop.image.loader.batik.PreloaderWMF with priority 1000
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.fop.image.loader.batik.PreloaderSVG with priority 1000
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/png, Flavor = RenderedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/png, Flavor = BufferedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/vnd.wap.wbmp, Flavor = RenderedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/vnd.wap.wbmp, Flavor = BufferedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/x-png, Flavor = RenderedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/x-png, Flavor = BufferedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/jpeg, Flavor = RenderedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/jpeg, Flavor = BufferedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/tiff, Flavor = RenderedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/tiff, Flavor = BufferedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/bmp, Flavor = RenderedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/bmp, Flavor = BufferedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/gif, Flavor = RenderedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/gif, Flavor = BufferedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryRaw: MIME = image/png, Flavor = image/png;Raw
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryRaw: MIME = image/jpeg, Flavor = image/jpeg;Raw
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryRaw: MIME = image/tiff, Flavor = image/tiff;Raw
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryRaw: MIME = image/x-emf, Flavor = image/x-emf;Raw
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryRawCCITTFax: MIME = image/tiff, Flavor = RawCCITTFax
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryEPS: MIME = application/postscript, Flavor = application/postscript;Raw
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryInternalTIFF: MIME = image/tiff, Flavor = RenderedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryPNG: MIME = image/png, Flavor = RenderedImage
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.fop.image.loader.batik.ImageLoaderFactorySVG: MIME = image/svg+xml, Flavor = text/xml;DOM;namespace=http://www.w3.org/2000/svg
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.fop.image.loader.batik.ImageLoaderFactoryWMF: MIME = image/x-wmf, Flavor = WMFRecordStore
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerConverter
FINE: Registered: org.apache.xmlgraphics.image.loader.impl.ImageConverterBuffered2Rendered
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerConverter
FINE: Registered: org.apache.xmlgraphics.image.loader.impl.ImageConverterG2D2Bitmap
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerConverter
FINE: Registered: org.apache.xmlgraphics.image.loader.impl.ImageConverterBitmap2G2D
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerConverter
FINE: Registered: org.apache.xmlgraphics.image.loader.impl.ImageConverterRendered2PNG
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerConverter
FINE: Registered: org.apache.fop.image.loader.batik.ImageConverterSVG2G2D
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerConverter
FINE: Registered: org.apache.fop.image.loader.batik.ImageConverterG2D2SVG
Nov 26, 2024 12:34:44 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerConverter
FINE: Registered: org.apache.fop.image.loader.batik.ImageConverterWMF2G2D

When in a jar (and doesn't work)

Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderTIFF with priority 1000
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderGIF with priority 1000
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderJPEG with priority 1000
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderBMP with priority 1000
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderEMF with priority 1000
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderEPS with priority 1000
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.PreloaderImageIO with priority 2000
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerPreloader
FINE: Registered org.apache.xmlgraphics.image.loader.impl.PreloaderRawPNG with priority 2000
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/png, Flavor = RenderedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/png, Flavor = BufferedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/vnd.wap.wbmp, Flavor = RenderedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/vnd.wap.wbmp, Flavor = BufferedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/x-png, Flavor = RenderedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/x-png, Flavor = BufferedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/jpeg, Flavor = RenderedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/jpeg, Flavor = BufferedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/tiff, Flavor = RenderedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/tiff, Flavor = BufferedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/bmp, Flavor = RenderedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/bmp, Flavor = BufferedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/gif, Flavor = RenderedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderFactoryImageIO: MIME = image/gif, Flavor = BufferedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryRaw: MIME = image/png, Flavor = image/png;Raw
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryRaw: MIME = image/jpeg, Flavor = image/jpeg;Raw
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryRaw: MIME = image/tiff, Flavor = image/tiff;Raw
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryRaw: MIME = image/x-emf, Flavor = image/x-emf;Raw
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryRawCCITTFax: MIME = image/tiff, Flavor = RawCCITTFax
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryEPS: MIME = application/postscript, Flavor = application/postscript;Raw
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryInternalTIFF: MIME = image/tiff, Flavor = RenderedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerLoaderFactory
FINE: Registered org.apache.xmlgraphics.image.loader.impl.ImageLoaderFactoryPNG: MIME = image/png, Flavor = RenderedImage
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerConverter
FINE: Registered: org.apache.xmlgraphics.image.loader.impl.ImageConverterBuffered2Rendered
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerConverter
FINE: Registered: org.apache.xmlgraphics.image.loader.impl.ImageConverterG2D2Bitmap
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerConverter
FINE: Registered: org.apache.xmlgraphics.image.loader.impl.ImageConverterBitmap2G2D
Nov 26, 2024 12:37:49 PM org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry registerConverter
FINE: Registered: org.apache.xmlgraphics.image.loader.impl.ImageConverterRendered2PNG

[edit2]

Might be onto something. The image preloaders are identified using xmlgraphics org.apache.xmlgraphics.util.Service class which scans through files in the META-INF.services dir within the jar. In fop-core.jar/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader is:

org.apache.fop.image.loader.batik.PreloaderWMF
org.apache.fop.image.loader.batik.PreloaderSVG

and in xmlgraphics-commons-2.10.jar/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader is

org.apache.xmlgraphics.image.loader.impl.PreloaderTIFF
org.apache.xmlgraphics.image.loader.impl.PreloaderGIF
org.apache.xmlgraphics.image.loader.impl.PreloaderJPEG
org.apache.xmlgraphics.image.loader.impl.PreloaderBMP
org.apache.xmlgraphics.image.loader.impl.PreloaderEMF
org.apache.xmlgraphics.image.loader.impl.PreloaderEPS
org.apache.xmlgraphics.image.loader.impl.imageio.PreloaderImageIO
org.apache.xmlgraphics.image.loader.impl.PreloaderRawPNG

So if I mush together the various jars with the assembly plugin, only one of the relevant service files will survive - in this case it looks like the latter one.


Solution

  • This issue is due to the fact that there are two libraries (fop-core-2.10.jar and xmlgraphics-common-2.10.jar) that contain the same spi files in the META-INF/services files, precisely:

    • org.apache.xmlgraphics.image.loader.spi.ImageConverter
    • org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory
    • org.apache.xmlgraphics.image.loader.spi.ImagePreloader

    Using the maven-assembly-plugin leads to have only the copy from one of the two libraries to be written into the final jar.

    I suggest you to replace the assembly whit the maven-shade-plugin that instead can merge / append the contents of matching files, like this:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.6.0</version>
      <executions>
        <execution>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
            <transformers>
              <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
            </transformers>
          </configuration>
        </execution>
      </executions>
    </plugin>
    

    Take a look also to the documentation page (https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#ServicesResourceTransformer) and also this other question (maven Assembly plugin is not appending/merging META-INF/services/ spi.AutoDiscoverable).