今天把项目部署在centos7上,发现验证码显示不出来,看了一下tomcat日志
Exception in thread "http-nio-8080-exec-3" java.lang.InternalError: java.lang.reflect.InvocationTargetException
at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.desktop/java.awt.Font.getFont2D(Font.java:497)
at java.desktop/java.awt.Font$FontAccessImpl.getFont2D(Font.java:237)
at java.desktop/sun.font.FontUtilities.getFont2D(FontUtilities.java:139)
at java.desktop/sun.java2d.SunGraphics2D.checkFontInfo(SunGraphics2D.java:670)
at java.desktop/sun.java2d.SunGraphics2D.getFontInfo(SunGraphics2D.java:831)
at java.desktop/sun.java2d.pipe.GlyphListPipe.drawString(GlyphListPipe.java:46)
at java.desktop/sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2929)
at com.itheima.travel.web.servlet.PicCodeServlet.doPost(PicCodeServlet.java:55)
at com.itheima.travel.web.servlet.PicCodeServlet.doGet(PicCodeServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
Exception in thread "http-nio-8080-exec-3" java.lang.InternalError: java.lang.reflect.InvocationTargetException at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74) at java.desktop/java.awt.Font.getFont2D(Font.java:497) at java.desktop/java.awt.Font$FontAccessImpl.getFont2D(Font.java:237) at java.desktop/sun.font.FontUtilities.getFont2D(FontUtilities.java:139) at java.desktop/sun.java2d.SunGraphics2D.checkFontInfo(SunGraphics2D.java:670) at java.desktop/sun.java2d.SunGraphics2D.getFontInfo(SunGraphics2D.java:831) at java.desktop/sun.java2d.pipe.GlyphListPipe.drawString(GlyphListPipe.java:46) at java.desktop/sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2929) at com.itheima.travel.web.servlet.PicCodeServlet.doPost(PicCodeServlet.java:55) at com.itheima.travel.web.servlet.PicCodeServlet.doGet(PicCodeServlet.java:75) at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
发现应该是字体问题,windows下的字体在centos上并没有.
1,首先把需要的字体复制到**“/usr/share/fonts”**目录中
2,修改字体文件的权限,使root用户以外的用户也可以使用:
cd /usr/share/fonts/windows
chmod 755 *.ttc
3,建立字体缓存
mkfontscale (如果提示 命令不存在,安装 # yum install mkfontscale )
mkfontdir
fc-cache -fv (如果提示 命令不存在,安装# yum install fontconfig )
4、重启计算机
解决