用Apache FOP JDK 11在Linux系统上使用sun.awt.FontConfiguration.getVersion会出现NPE。

9

我正在使用Apache FOP(版本为2.3,测试版本为2.5)。我最近从Oracle JDK 8升级到Oracle JDK 11。我在Oracle Linux上使用JBoss EAP 7.2(它是RedHat衍生产品)。当使用JDK 8时,一切正常,但仅升级到JDK 11就导致我的FOP XSLT用于XML-> PDF和XML-> PNG创建以下堆栈跟踪(FOP版本不重要,因为会产生相同的错误)。

Caused by: java.lang.NullPointerException
        at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262)
        at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225)
        at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:107)
        at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:719)

我的字体是Google/RedHat的LiberationSans,我已将它们放在文件系统中,并在名为LiberationSans.xconf的文件中进行了配置。我确保文件可以被全局读取(775),并且是由运行JBoss实例的用户拥有。

<?xml version="1.0"?>
<!-- LiberationSans -->
<fop version="1.0">
  <renderers>
    <renderer mime="application/pdf">
      <fonts>
        <font embed-url="/apps/fonts/LiberationSans-Regular.ttf" embedding-mode="subset">
          <font-triplet name="LiberationSans" style="normal" weight="normal"/>
        </font>
        <font embed-url="/apps/fonts/LiberationSans-Bold.ttf" embedding-mode="subset">
          <font-triplet name="LiberationSans" style="normal" weight="bold"/>
        </font>
      </fonts>
    </renderer>
    <renderer mime="image/png">
      <fonts>
       <font embed-url="/apps/fonts/LiberationSans-Regular.ttf" embedding-mode="subset">
          <font-triplet name="LiberationSans" style="normal" weight="normal"/>
        </font>
        <font embed-url="/apps/fonts/LiberationSans-Bold.ttf" kerning="yes" embedding-mode="subset">
          <font-triplet name="LiberationSans" style="normal" weight="bold"/>
        </font>
      </fonts>
    </renderer>
  </renderers>
</fop>

我的本地windows电脑上一切正常,但我的部署是通过Eclipse/JBoss插件进行的,所以可能与此有关。在Linux服务器上的部署是通过jboss-cli进行的。

请告诉我是否还有其他信息可以提供,可能有助于解决问题。如果我们必须迁移离开FOP,我希望这是最后的选择。

1个回答

18

事实证明,问题并不是我无法访问字体,而是Linux操作系统要求我通过yum安装fontconfig。

yum install fontconfig

我不确定为什么在我的生产环境中使用Oracle JDK 1.8并且没有安装fontconfig时,Oracle JDK 11加上缺失的Linux实用程序是问题所在。


2
一些极简发行版(例如Alpine)可能还需要一些字体包,例如ttf-dejavu - tokland
1
@tokland 如何安装ttf-dejavu? - user1689987

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接