Skip to content

LibreOffice 转换部分文件格式失败,偶发提示 Warning: failed to launch javaldx - java may not function correctly

使用 LibreOffice 转换 PPTX 为 PDF 格式时,偶发提示:Warning: failed to launch javaldx - java may not function correctly,记录下修复方法。


环境说明

  • Ubuntu 24.04.3 LTS

安装 LibreOffice

笔者只是需要使用程序调用 LibreOffice 的文档转换能力。

shell
apt-get update
apt-get install -y --no-install-recommends \
    libreoffice \
    libreoffice-writer \
    libreoffice-calc \
    libreoffice-impress \
    libreoffice-base \
    libreoffice-draw \
    fonts-wqy-zenhei \
apt-get clean && rm -rf /var/lib/apt/lists/*

转换文档格式

shell
# --headless:用于以无头模式运行,即不显示图形用户界面,通常用于自动化任务
# --nologo‌:隐藏启动时的程序 Logo 界面,使启动过程更简洁,适用于自动化任务
# --nofirststartwizard‌:跳过首次启动时的向导或注册界面,防止在无人值守模式下因等待用户输入而阻塞
soffice --headless --nologo --nofirststartwizard --convert-to pdf --outdir /tmp/outputs /path/to/file.pptx

执行上述命令,偶发会提示如下警告。

text
Warning: failed to launch javaldx - java may not function correctly

安装 libreoffice-java-common 组件

根据 AI 及查找的结果,以及错误字面意思,是缺少 Java 环境或相关组件。

尝试在原安装命令基础上,增加安装 libreoffice-java-common 组件。

shell
apt-get install -y libreoffice-java-common

安装 JRE

重新执行转换文档格式命令,结果又提示如下错误:字面意思就是缺少 JRE 环境。

text
javaldx: Could not find a Java Runtime Environment!
Please ensure that a JVM and the package libreoffice-java-common is installed.
If it is already installed then try removing ~/.config/libreoffice/4/user/config/javasettings_Linux_*.xml
Warning: failed to read path from javaldx

继续在原安装命令基础上,增加安装 default-jre(最新可用的 JRE) 或指定 JRE 依赖。

shell
apt-get install -y default-jre

再次执行就没有提示了。

完整执行命令。

shell
apt-get update
apt-get install -y --no-install-recommends \
    libreoffice \
    libreoffice-writer \
    libreoffice-calc \
    libreoffice-impress \
    libreoffice-base \
    libreoffice-draw \
    libreoffice-java-common \
    default-jre \
    fonts-wqy-zenhei \
apt-get clean && rm -rf /var/lib/apt/lists/*

温馨提示

如果使用程序批量进行文件转换,可增加互斥锁,防止同时调用 soffice 命令,避免进程冲突。

参考资料

  1. 在Ubuntu中打开LibreOffice报错:Warning: failed to launch javaldx - java may not function correctly:https://blog.csdn.net/panghuangang/article/details/128434714
  2. ubuntu20.04安装liberoffice:https://blog.csdn.net/yixinluobo/article/details/123522987