You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Oracle JDK11环境下Apache FOP报FontConfiguration.getVersion空指针问题求助

Fixing Apache FOP NullPointerException with JDK 11 on Oracle Linux (JBoss EAP 7.2)

I’ve run into this exact problem when upgrading from JDK 8 to 11 with Apache FOP on RHEL-based server environments, so let’s walk through the most effective fixes step by step:

1. Install System-Level Fontconfig Dependencies

JDK 11 removed the bundled font configuration libraries that came with JDK 8, and now relies entirely on the system’s fontconfig package. This is often missing on minimal server installs of Oracle Linux. Run this as root to install it:

yum install fontconfig

Once installed, restart your JBoss EAP instance. This resolves the core issue where the JDK can’t locate system font configuration files.

2. Explicitly Define the Font Config Path for JBoss

If installing fontconfig alone doesn’t fix the error, you can force the JDK to use the system’s font config file directly by adding a system property to JBoss’s startup script. Edit your standalone.conf (or domain.conf if using domain mode) and add this line to the JAVA_OPTS section:

JAVA_OPTS="$JAVA_OPTS -Dsun.awt.fontconfig=/etc/fonts/fonts.conf"

This bypasses any auto-detection quirks and ensures the JDK knows exactly where to find font configuration data.

3. Ensure FOP’s Custom Font Configuration Is Loaded Correctly

Even with your LiberationSans.xconf set up, make sure FOP is actually picking it up in your application code. Initialize the FOP Factory with an explicit path to your config file:

FopFactory fopFactory = FopFactory.newInstance(new File("/path/to/your/LiberationSans.xconf"));

Also double-check permissions: confirm the JBoss run user has read access to both the font files (/apps/fonts/*.ttf) and the FOP config file. Even if permissions are set to 775, verify the user is part of the group that owns these files.

4. Adjust JBoss EAP Module Permissions for AWT Classes

JBoss EAP 7.2’s module system may restrict access to AWT-related classes by default, which are required for FOP’s font processing. To fix this:

  1. Create a module file at modules/system/layers/base/java/desktop/main/module.xml with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<module name="java.desktop" xmlns="urn:jboss:module:1.3">
    <resources>
        <resource-root path="."/>
    </resources>
    <dependencies>
        <module name="java.base"/>
        <module name="java.logging"/>
    </dependencies>
</module>
  1. Add this module dependency to your application’s jboss-deployment-structure.xml:
<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="java.desktop" export="true"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

This makes the necessary AWT classes available to your application.

Why This Happens

JDK 8 included bundled font configuration data, but JDK 11 shifted to using the system’s fontconfig library. On headless Linux servers (like those running JBoss), fontconfig is often not installed by default, leading to the NullPointerException when the JDK tries to read font config data. Additionally, JBoss’s strict module system can block access to AWT classes needed for FOP to process fonts.

Verification Steps

After applying these fixes:

  • Test the XML-to-PDF/PNG conversion with a standalone Java program on the server (outside JBoss) to rule out deployment-specific issues.
  • Check JBoss’s server logs to confirm no more font-related exceptions appear.
  • Open a generated document to verify the LiberationSans font is embedded correctly.

内容的提问来源于stack exchange,提问作者javafreak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:23:38