项目打jar包在服务器运行时,生成的图片中文全是方格,因为Linux上没有对应的字体文件,
安装字体文件
1、在本地Windows电脑上C:\Windows\Fonts 下面的字体文件全部复制,也可以单独复制需要的字体,复制后要删除所有的不是ttc、ttf的文件,不然无法执行安装命令
2、在服务器新建文件夹来存放字体文件 例如 /usr/local/share/fonts
cd /usr/local/share
mkdir fonts
3、然后进入该目录,依次执行以下命令
mkfontscale // 安装字体
mkfontdir
fc-cache // 更新字体
执行完后可通过 fc-list命令查看当前系统具有的字体,接下来重启jar包就可以了!
执行命令如果报错
-bash: mkfontscale: command not found ,
-bash: fc-cache: command not found
需要安装mkfontscale、fontconfig
yum install mkfontscale yum install fontconfig
5、在安装mkfontscale时报错
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki article https://wiki.centos.org/yum-errorsIf above article doesn't help to resolve this issue please use https://bugs.centos.org/.One of the configured repositories failed (CentOS-7 - Base),and yum doesn't have enough cached data to continue. At this point the onlysafe thing yum can do is fail. There are a few ways to work "fix" this:1. Contact the upstream for the repository and get them to fix the problem.2. Reconfigure the baseurl/etc. for the repository, to point to a workingupstream. This is most often useful if you are using a newerdistribution release than is supported by the repository (and thepackages for the previous distribution release still work).3. Run the command with the repository temporarily disabledyum --disablerepo=base ...4. Disable the repository permanently, so yum won't use it by default. Yumwill then just ignore the repository until you permanently enable itagain or use --enablerepo for temporary usage:yum-config-manager --disable baseorsubscription-manager repos --disable=base5. Configure the failing repository to be skipped, if it is unavailable.Note that yum will try to contact the repo. when it runs most commands,so will have to try and fail each time (and thus. yum will be be muchslower). If it is a very temporary problem though, this is often a nicecompromise:yum-config-manager --save --setopt=base.skip_if_unavailable=truefailure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.
https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
这个时候就不要想起他的了,反正我是搞了一天,最后直接rm了/etc/yum.repos.d 下面的所有文件,也就是按照文档说的换yum源,不过换源前建议还是备份一下比较好
cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bf
3、通过wget进行下载在线yum源
cd /etc/yum.repos.d/
阿里云地址
wget http://mirrors.aliyun.com/repo/Centos-7.repo
下载完成后会看到 Centos-7.repo 文件,然后再次执行mkfontscale的安装,继续上面的字体安装步骤