Java 字体对于Docker容器中带有Jasper报告的JVM不可用
我正在尝试在Docker容器中使用DynamicAsper生成报告? 如果我得到以下错误:Java 字体对于Docker容器中带有Jasper报告的JVM不可用,java,docker,fonts,jasper-reports,Java,Docker,Fonts,Jasper Reports,我正在尝试在Docker容器中使用DynamicAsper生成报告? 如果我得到以下错误: net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'Arial' is not available to the JVM. 如何修复此问题?我使用了下面的Dockerfile,问题得到了解决。 我尝试在容器中的文件系统中搜索字体,使用: ls /usr/
net.sf.jasperreports.engine.util.JRFontNotFoundException:
Font 'Arial' is not available to the JVM.
如何修复此问题?我使用了下面的Dockerfile,问题得到了解决。 我尝试在容器中的文件系统中搜索字体,使用:
ls /usr/share/fonts/truetype/msttcorefonts/
我可以看到文件夹中加载的字体
FROM openjdk:8u141-jre
COPY /build/libs/my-app*.jar /my-app.jar
EXPOSE 9500
RUN apt-get update && apt-get install -y vim
RUN echo "deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty multiverse deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty-updates multiverse deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse" | tee /etc/apt/sources.list.d/multiverse.list
RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections
RUN ["apt-get", "-y", "install", "ttf-mscorefonts-installer"]
RUN dpkg-reconfigure ttf-mscorefonts-installer
RUN apt-get install -y apt-transport-https apt-utils
RUN apt-get install --reinstall -y ttf-mscorefonts-installer
CMD java -XX:+PrintFlagsFinal $JAVA_OPTS -jar /my-app.jar
我使用了下面的Dockerfile,问题就解决了。 我尝试在容器中的文件系统中搜索字体,使用:
ls /usr/share/fonts/truetype/msttcorefonts/
我可以看到文件夹中加载的字体
FROM openjdk:8u141-jre
COPY /build/libs/my-app*.jar /my-app.jar
EXPOSE 9500
RUN apt-get update && apt-get install -y vim
RUN echo "deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty multiverse deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty-updates multiverse deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse" | tee /etc/apt/sources.list.d/multiverse.list
RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections
RUN ["apt-get", "-y", "install", "ttf-mscorefonts-installer"]
RUN dpkg-reconfigure ttf-mscorefonts-installer
RUN apt-get install -y apt-transport-https apt-utils
RUN apt-get install --reinstall -y ttf-mscorefonts-installer
CMD java -XX:+PrintFlagsFinal $JAVA_OPTS -jar /my-app.jar
基本上,JVM本身不包含任何字体。这就是为什么你必须自己安装它们。你的解决方案似乎已经很好了。对于基于Debian的Docker映像,我执行以下操作:
#Add non-free repositories to get MS fonts
RUN apt-get update
RUN apt-get install -y --no-install-recommends software-properties-common
RUN apt-add-repository contrib
RUN apt-get update
# If you want to use Microsoft fonts in reports, you must install the fonts
# Andale Mono, Arial Black, Arial, Comic Sans MS, Courier New, Georgia, Impact,
# Times New Roman, Trebuchet, Verdana,Webdings)
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
RUN apt-get install -y --no-install-recommends fontconfig ttf-mscorefonts-installer
ADD localfonts.conf /etc/fonts/local.conf
RUN fc-cache -f -v
# If you want to use special characters, such as chinese ideograms, you must install a
font that support them
# For example:
RUN apt install -y fonts-wqy-zenhei
localfonts.conf文件是一个优化的文件,用于调整“msttcorefonts”集合的一些抗锯齿规则。你可以在这里找到它:
不幸的是,文件长度太长,无法在上面共享,但假设我发布的链接将保留在Ubuntu wiki上是合理的。基本上,JVM本身不包含任何字体。这就是为什么你必须自己安装它们。你的解决方案似乎已经很好了。对于基于Debian的Docker映像,我执行以下操作:
#Add non-free repositories to get MS fonts
RUN apt-get update
RUN apt-get install -y --no-install-recommends software-properties-common
RUN apt-add-repository contrib
RUN apt-get update
# If you want to use Microsoft fonts in reports, you must install the fonts
# Andale Mono, Arial Black, Arial, Comic Sans MS, Courier New, Georgia, Impact,
# Times New Roman, Trebuchet, Verdana,Webdings)
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
RUN apt-get install -y --no-install-recommends fontconfig ttf-mscorefonts-installer
ADD localfonts.conf /etc/fonts/local.conf
RUN fc-cache -f -v
# If you want to use special characters, such as chinese ideograms, you must install a
font that support them
# For example:
RUN apt install -y fonts-wqy-zenhei
localfonts.conf文件是一个优化的文件,用于调整“msttcorefonts”集合的一些抗锯齿规则。你可以在这里找到它:
不幸的是,文件的长度太长,无法在上面共享,但假设我发布的链接将保留在Ubuntu wiki上是合理的。这有助于我使用基于Debian的Docker图像
RUN apt-get -q update \
&& apt-get -q install -y cabextract libmspack0 \
&& wget http://ftp.de.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.6_all.deb \
&& dpkg -i ttf-mscorefonts-installer_3.6_all.deb
这有助于我处理基于Debian的Docker映像
RUN apt-get -q update \
&& apt-get -q install -y cabextract libmspack0 \
&& wget http://ftp.de.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.6_all.deb \
&& dpkg -i ttf-mscorefonts-installer_3.6_all.deb
当我使用你的文件时,我得到一个错误,比如:E:无法找到ttf mscorefonts安装程序包,我想基于debian和ubuntu的安装程序是不同的。你的图像是基于debian还是基于ubuntu?我的图像是基于ubuntu的。非常感谢你的建议!当我使用你的文件时,我得到一个错误,比如:E:无法找到ttf mscorefonts安装程序包,我想基于debian和ubuntu的安装程序是不同的。你的图像是基于debian还是基于ubuntu?我的图像是基于ubuntu的。非常感谢你的建议!