AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题 / 79226319
Accepted
Peter Hull
Peter Hull
Asked: 2024-11-26 18:36:17 +0800 CST2024-11-26 18:36:17 +0800 CST 2024-11-26 18:36:17 +0800 CST

如果 SVG 位于 jar 中,Apache FOP/Xmlgraphics 则无法加载它

  • 772

我有一个使用 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 与组装插件混合在一起,那么只有一个相关的服务文件能够存活下来 - 在这种情况下,它看起来像后者。

java
  • 1 1 个回答
  • 29 Views

1 个回答

  • Voted
  1. Best Answer
    Francesco Poli
    2024-11-26T22:14:04+08:002024-11-26T22:14:04+08:00

    该问题是由于有两个库(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我建议您用可以合并/附加匹配文件内容的程序集替换它,如下所示:

    <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>
    

    还请查看文档页面(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)。

    • 1

相关问题

  • Lock Condition.notify 抛出 java.lang.IllegalMonitorStateException

  • 多对一微服务响应未出现在邮递员中

  • 自定义 SpringBoot Bean 验证

  • Java 套接字是 FIFO 的吗?

  • 为什么不可能/不鼓励在服务器端定义请求超时?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    为什么这个简单而小的 Java 代码在所有 Graal JVM 上的运行速度都快 30 倍,但在任何 Oracle JVM 上却不行?

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    何时应使用 std::inplace_vector 而不是 std::vector?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Marko Smith

    我正在尝试仅使用海龟随机和数学模块来制作吃豆人游戏

    • 1 个回答
  • Martin Hope
    Aleksandr Dubinsky 为什么 InetAddress 上的 switch 模式匹配会失败,并出现“未涵盖所有可能的输入值”? 2024-12-23 06:56:21 +0800 CST
  • Martin Hope
    Phillip Borge 为什么这个简单而小的 Java 代码在所有 Graal JVM 上的运行速度都快 30 倍,但在任何 Oracle JVM 上却不行? 2024-12-12 20:46:46 +0800 CST
  • Martin Hope
    Oodini 具有指定基础类型但没有枚举器的“枚举类”的用途是什么? 2024-12-12 06:27:11 +0800 CST
  • Martin Hope
    sleeptightAnsiC `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它? 2024-11-09 07:18:53 +0800 CST
  • Martin Hope
    The Mad Gamer 何时应使用 std::inplace_vector 而不是 std::vector? 2024-10-29 23:01:00 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST
  • Martin Hope
    MarkB 为什么 GCC 生成有条件执行 SIMD 实现的代码? 2024-02-17 06:17:14 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve