错误提示:
SEVERE: Servlet.service() for servlet [example] in context with path [/myproject] threw exception [Request processing failed; nested exception is net.sf.jasperreports.engine.util.JRFontNotFoundException: Font ‘宋体‘ is not available to the JVM. See the Javadoc for more details.] with root cause
net.sf.jasperreports.engine.util.JRFontNotFoundException: Font ‘宋体‘ is not available to the JVM. See the Javadoc for more details.
at net.sf.jasperreports.engine.fonts.FontUtil.checkAwtFont(FontUtil.java:356)
at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.loadFont(SimpleTextLineWrapper.java:368)
at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.getGeneralFontInfo(SimpleTextLineWrapper.java:338)
at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.createFontInfo(SimpleTextLineWrapper.java:278)
at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.start(SimpleTextLineWrapper.java:240)
at net.sf.jasperreports.engine.fill.TextMeasurer.measure(TextMeasurer.java:536)
at net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:670)
at net.sf.jasperreports.engine.fill.JRFillTextField.prepare(JRFillTextField.java:767)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:330)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:382)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:357)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillBandNoOverflow(JRVerticalFiller.java:433)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVerticalFiller.java:396)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:257)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:123)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:539)
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:411)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:115)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:667)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:983)
at org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.fillReport(AbstractJasperReportsView.java:676)
at com.opensourcedata.admin.controller.ApplicationIReportView.fillReport(ApplicationIReportView.java:28)
at org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.renderMergedOutputModel(AbstractJasperReportsView.java:561)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1221)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.opensourcedata.filter.SessionFilter.doFilterInternal(SessionFilter.java:62)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
解决方案:
1. 符合windows下的字体文件, 因为缺少的是宋体, 那么就将宋体, 复制到服务器上
2. 进入jsp项目的classes目录下
[[email protected] ~]# cd /usr/share/tomcat/webapps/myproject/WEB-INF/classes/
[[email protected] classes]# ls
applicationContext.xml com config.properties ehcache-hibernate.xml log4j.xml
3. 复制刚才上传的字体文件到该目录下
[[email protected] classes]# cp ~/SIMSUNB.TTF .
l[[email protected] classes]# ls
applicationContext.xml com config.properties ehcache-hibernate.xml log4j.xml SIMSUNB.TTF
4. 编辑一个jasperreports.properties文件
[[email protected] classes]# vim jasperreports.properties
在该文件中输入以下内容:
net.sf.jasperreports.awt.ignore.missing.font=true
5. 重启tomcat服务
[[email protected] ~]# systemctl restart tomcat.service
解决Centos 7 下 tomcat字体异常 Font '宋体' is not available to the JVM