我有一个使用 Apache FOP 创建 PDF 的应用程序,其中包含一个 SVG 图像(它是一个徽标,每次都一样),我发现如果我使用 Maven 的 assembly 插件创建一个带有依赖项的 jar,它就不会包含该图像。我做了一些工作来缩小范围,似乎当应用程序在 jar 中时,SVG 图像加载器没有注册 - 所以它不是 FOP 的 PDF 部分,而是 xmlgraphics-commons 中的 ImageManager。
我在下面粘贴了一个最小的例子,它需要当前目录中名为img.png
、img.tiff
和 的文件。img.svg
如果你运行它,mvn exec:java
它会打印出
image (image/png)
image (image/tiff)
image (image/svg+xml)
如果你跑mvn package
,然后java -cp .\target\mavenproject2-1.0-SNAPSHOT-jar-with-dependencies.jar project.Mavenproject2
你得到
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
因此 SVG 加载器不可用。
有没有办法告诉 FOP 注册该 SVG 加载器,否则无法从具有依赖项的 jar 中运行它,我应该考虑以其他方式打包应用程序?
最小示例代码:
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;
}
}
和 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>
在 Windows11 上使用 maven 3.9.9。
[编辑] 根据@francesco-poli 的要求记录日志,当不在 jar 中时(它可以工作)
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
放在罐子里(不起作用)
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
[编辑2]
可能发现了什么。图像预加载器使用 xmlgraphics 类进行识别org.apache.xmlgraphics.util.Service
,该类扫描 jar 中的 META-INF.services 目录中的文件。在 fop-core.jar/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader 中:
org.apache.fop.image.loader.batik.PreloaderWMF
org.apache.fop.image.loader.batik.PreloaderSVG
并且在 xmlgraphics-commons-2.10.jar/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader 中
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
所以如果我将各种 jar 与组装插件混合在一起,那么只有一个相关的服务文件能够存活下来 - 在这种情况下,它看起来像后者。
该问题是由于有两个库(
fop-core-2.10.jar
和xmlgraphics-common-2.10.jar
)在文件中包含相同的 spi 文件META-INF/services
,确切地说:org.apache.xmlgraphics.image.loader.spi.ImageConverter
org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory
org.apache.xmlgraphics.image.loader.spi.ImagePreloader
使用
maven-assembly-plugin
线索只将两个库中的一个库的副本写入最终的 jar 中。maven-shade-plugin
我建议您用可以合并/附加匹配文件内容的程序集替换它,如下所示:还请查看文档页面(https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#ServicesResourceTransformer)以及另一个问题(maven Assembly plugin is not appending/merging META-INF/services/spi.AutoDiscoverable)。