当前位置: 首页 > article >正文

Graphics2D 打包在Linux运行时中文乱码,展示成方格

项目打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-errors

If 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 only
 safe 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 working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=base ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable base
        or
            subscription-manager repos --disable=base

     5. 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 much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=base.skip_if_unavailable=true

failure: 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的安装,继续上面的字体安装步骤


http://www.kler.cn/news/343344.html

相关文章:

  • JavaScript轮播图实现
  • 两个数相加(c语言)
  • MySQL修改字段卡住问题总结及解决方法
  • hive数据库||的用法、hive数据库字符串拼接、concat函数、concat_ws函数
  • Patroni配置3-环境变量配置设置
  • 【操作系统】四、文件管理:1.文件系统基础(文件属性、文件逻辑结构、文件物理结构、文件存储管理、文件目录、基本操作、文件共享、文件保护)
  • QT C++ 软键盘/悬浮键盘/触摸屏键盘的制作
  • leetcode:反转字符串中的单词III
  • 2024年秋季学期期中考试成绩查询系统-老师制作工具
  • ECharts图表图例5
  • C++——反向迭代器
  • 【Linux探索学习】第四弹——Linux权限管理详解:理解用户、组和权限之间的关系
  • leetcode 131 分割回文串
  • SQL调优指南与高级技巧:打造高效数据库查询
  • Leetcode 删除链表倒数第 N 个节点
  • 【Golang】Go语言Seeker接口与文件断点续传实战
  • 【Linux实践】实验七:vi编辑器的使用
  • 在 TypeScript 中判断两个类型相等的挑战
  • 从分布 P 中抽取随机变量 X的期望值
  • 七、Python基础语法(判断语句 上)