字体在 Docker 容器中的 Jasper Reports 中对 JVM 不可用。

huangapple go评论175阅读模式
英文:

Font is not available to the JVM with Jasper Reports in Docker Container

问题

我正在尝试在Docker容器中使用DynamicJasper生成报表。
如果我遇到以下错误:

  1. net.sf.jasperreports.engine.util.JRFontNotFoundException:
  2. 字体'Arial'JVM不可用。

我该如何解决这个问题?

英文:

I'm trying to generate a report with DynamicJasper in Docker container?
If I get the followfing error:

  1. net.sf.jasperreports.engine.util.JRFontNotFoundException:
  2. Font 'Arial' is not available to the JVM.

How can I fix this?

答案1

得分: 3

我使用了类似下面的 Dockerfile,问题得以解决。
我尝试在容器中的文件系统中搜索字体,使用以下命令:

  1. ls /usr/share/fonts/truetype/msttcorefonts/

我可以看到字体加载在这个文件夹中。

  1. FROM openjdk:8u141-jre
  2. COPY /build/libs/my-app*.jar /my-app.jar
  3. EXPOSE 9500
  4. RUN apt-get update && apt-get install -y vim
  5. 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
  6. RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections
  7. RUN ["apt-get", "-y", "install", "ttf-mscorefonts-installer"]
  8. RUN dpkg-reconfigure ttf-mscorefonts-installer
  9. RUN apt-get install -y apt-transport-https apt-utils
  10. RUN apt-get install --reinstall -y ttf-mscorefonts-installer
  11. CMD java -XX:+PrintFlagsFinal $JAVA_OPTS -jar /my-app.jar
英文:

I used a Dockerfile like the one below and the problem was solved.
I tried searching for the font in the filesystem in container, with:

  1. ls /usr/share/fonts/truetype/msttcorefonts/

I can see the fonts loaded the folder.

  1. FROM openjdk:8u141-jre
  2. COPY /build/libs/my-app*.jar /my-app.jar
  3. EXPOSE 9500
  4. RUN apt-get update && apt-get install -y vim
  5. 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
  6. RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections
  7. RUN ["apt-get", "-y", "install", "ttf-mscorefonts-installer"]
  8. RUN dpkg-reconfigure ttf-mscorefonts-installer
  9. RUN apt-get install -y apt-transport-https apt-utils
  10. RUN apt-get install --reinstall -y ttf-mscorefonts-installer
  11. CMD java -XX:+PrintFlagsFinal $JAVA_OPTS -jar /my-app.jar

答案2

得分: 2

以下是翻译好的内容:

实际上,JVM本身不包含任何字体。这就是为什么您需要自己安装它们。您的解决方案似乎已经很好。对于基于Debian的Docker镜像,我执行以下操作:

  1. #添加非自由存储库以获取微软字体
  2. RUN apt-get update
  3. RUN apt-get install -y --no-install-recommends software-properties-common
  4. RUN apt-add-repository contrib
  5. RUN apt-get update
  6. #如果您想在报告中使用Microsoft字体,必须安装字体
  7. Andale MonoArial BlackArialComic Sans MSCourier NewGeorgiaImpact
  8. Times New RomanTrebuchetVerdanaWebdings
  9. RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
  10. RUN apt-get install -y --no-install-recommends fontconfig ttf-mscorefonts-installer
  11. ADD localfonts.conf /etc/fonts/local.conf
  12. RUN fc-cache -f -v
  13. #如果您想要使用特殊字符,比如汉字,您必须安装一个支持它们的字体
  14. #例如:
  15. RUN apt install -y fonts-wqy-zenhei

localfonts.conf文件是为调整'msttcorefonts'集合的一些抗锯齿规则而优化的。您可以在此处找到它:https://wiki.ubuntu.com/Fonts#Manual_Font_Smoothing
不幸的是,文件长度太长,无法在SO上共享,但可以合理地假设我发布的链接将保存在Ubuntu维基上。

英文:

Essentially, the JVM itself does not hold any font. That's why you have to install them by yourself. Your solution seems already good. For Debian-based Docker images I do the following:

  1. #Add non-free repositories to get MS fonts
  2. RUN apt-get update
  3. RUN apt-get install -y --no-install-recommends software-properties-common
  4. RUN apt-add-repository contrib
  5. RUN apt-get update
  6. # If you want to use Microsoft fonts in reports, you must install the fonts
  7. # Andale Mono, Arial Black, Arial, Comic Sans MS, Courier New, Georgia, Impact,
  8. # Times New Roman, Trebuchet, Verdana,Webdings)
  9. RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
  10. RUN apt-get install -y --no-install-recommends fontconfig ttf-mscorefonts-installer
  11. ADD localfonts.conf /etc/fonts/local.conf
  12. RUN fc-cache -f -v
  13. # If you want to use special characters, such as chinese ideograms, you must install a
  14. font that support them
  15. # For example:
  16. RUN apt install -y fonts-wqy-zenhei

The localfonts.conf file is an optimized for tweaking some anti-aliasing rules for the 'msttcorefonts' collection. Yo can find it here: https://wiki.ubuntu.com/Fonts#Manual_Font_Smoothing
Unfortunatly the file length is too file to share it on SO, but it's resonable to suppose that the link I posted will be kept on Ubuntu wiki.

答案3

得分: 0

这帮助我解决了关于我的基于Debian的Docker镜像的问题:

  1. RUN apt-get -q update \
  2. && apt-get -q install -y cabextract libmspack0 \
  3. && wget http://ftp.de.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.6_all.deb \
  4. && dpkg -i ttf-mscorefonts-installer_3.6_all.deb
英文:

This helped me with my Debian-based Docker image

  1. RUN apt-get -q update \
  2. && apt-get -q install -y cabextract libmspack0 \
  3. && wget http://ftp.de.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.6_all.deb \
  4. && dpkg -i ttf-mscorefonts-installer_3.6_all.deb

huangapple
  • 本文由 发表于 2020年8月25日 16:41:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63575114.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定