码成呆瓜 2024-01-31 00:43 采纳率: 10%
浏览 8

excel模板下载报错

java项目,将excel模板放入项目路径,在win环境可以正常读取,但是上传linux通过docker容器运行后直接报错,提示没有libfreetype.so.6,但是我找过是有这个中文字库的,所以想问问这个应该怎么解决


```java
com.alibaba.excel.exception.ExcelGenerateException: java.lang.UnsatisfiedLinkError: fontmanager (libfreetype.so.6: cannot open shared object file: No such file or directory)
    at com.alibaba.excel.write.ExcelBuilderImpl.(ExcelBuilderImpl.java:42)
    at com.alibaba.excel.ExcelWriter.(ExcelWriter.java:36)
    at com.alibaba.excel.write.builder.ExcelWriterBuilder.build(ExcelWriterBuilder.java:114)
    at com.baiyuan.sales.commodities.core.controller.SalesSlipInfoController.templateDownload(SalesSlipInfoController.java:446)
    at com.baiyuan.sales.commodities.core.controller.SalesSlipInfoController$$FastClassBySpringCGLIB$$50659066.invoke()
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
    at com.baiyuan.sales.commodities.core.controller.SalesSlipInfoController$$EnhancerBySpringCGLIB$$efb4ac30.templateDownload()
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: fontmanager (libfreetype.so.6: cannot open shared object file: No such file or directory)
    at java.lang.ClassLoader.loadLibraryWithPath(Unknown Source)
    at java.lang.ClassLoader.loadLibraryWithClassLoader(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at sun.font.FontManagerNativeLibrary$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Unknown Source)
    at sun.font.FontManagerNativeLibrary.(Unknown Source)
    at sun.font.SunFontManager$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Unknown Source)
    at sun.font.SunFontManager.(Unknown Source)
    at java.lang.Class.forNameImpl(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at sun.font.FontManagerFactory$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Unknown Source)
    at sun.font.FontManagerFactory.getInstance(Unknown Source)
    at java.awt.Font.getFont2D(Unknown Source)
    at java.awt.Font.canDisplayUpTo(Unknown Source)
    at java.awt.font.TextLayout.singleFont(Unknown Source)
    at java.awt.font.TextLayout.(Unknown Source)
    at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:273)
    at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.(AutoSizeColumnTracker.java:117)
    at org.apache.poi.xssf.streaming.SXSSFSheet.(SXSSFSheet.java:82)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:684)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.(SXSSFWorkbook.java:247)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.(SXSSFWorkbook.java:211)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.(SXSSFWorkbook.java:186)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.(SXSSFWorkbook.java:161)
    at com.alibaba.excel.util.WorkBookUtil.createWorkBook(WorkBookUtil.java:40)
    at com.alibaba.excel.context.WriteContextImpl.(WriteContextImpl.java:96)
    at com.alibaba.excel.write.ExcelBuilderImpl.(ExcelBuilderImpl.java:36)
    ... 63 more
com.alibaba.excel.exception.ExcelGenerateException: java.lang.NoClassDefFoundError: sun.awt.X11FontManager (initialization failure)
    at com.alibaba.excel.write.ExcelBuilderImpl.(ExcelBuilderImpl.java:42)
    at com.alibaba.excel.ExcelWriter.(ExcelWriter.java:36)
    at com.alibaba.excel.write.builder.ExcelWriterBuilder.build(ExcelWriterBuilder.java:114)
    at com.baiyuan.sales.commodities.core.controller.SalesSlipInfoController.templateDownload(SalesSlipInfoController.java:446)
    at com.baiyuan.sales.commodities.core.controller.SalesSlipInfoController$$FastClassBySpringCGLIB$$50659066.invoke()
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
    at com.baiyuan.sales.commodities.core.controller.SalesSlipInfoController$$EnhancerBySpringCGLIB$$efb4ac30.templateDownload()
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: sun.awt.X11FontManager (initialization failure)
    at java.lang.J9VMInternals.initializationAlreadyFailed(Unknown Source)
    at java.lang.Class.forNameImpl(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at sun.font.FontManagerFactory$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Unknown Source)
    at sun.font.FontManagerFactory.getInstance(Unknown Source)
    at java.awt.Font.getFont2D(Unknown Source)
    at java.awt.Font.canDisplayUpTo(Unknown Source)
    at java.awt.font.TextLayout.singleFont(Unknown Source)
    at java.awt.font.TextLayout.(Unknown Source)
    at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:273)
    at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.(AutoSizeColumnTracker.java:117)
    at org.apache.poi.xssf.streaming.SXSSFSheet.(SXSSFSheet.java:82)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:684)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.(SXSSFWorkbook.java:247)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.(SXSSFWorkbook.java:211)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.(SXSSFWorkbook.java:186)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.(SXSSFWorkbook.java:161)
    at com.alibaba.excel.util.WorkBookUtil.createWorkBook(WorkBookUtil.java:40)
    at com.alibaba.excel.context.WriteContextImpl.(WriteContextImpl.java:96)
    at com.alibaba.excel.write.ExcelBuilderImpl.(ExcelBuilderImpl.java:36)
    ... 63 more
Caused by: java.lang.UnsatisfiedLinkError: fontmanager (libfreetype.so.6: cannot open shared object file: No such file or directory)
    at java.lang.ClassLoader.loadLibraryWithPath(Unknown Source)
    at java.lang.ClassLoader.loadLibraryWithClassLoader(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at sun.font.FontManagerNativeLibrary$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Unknown Source)
    at sun.font.FontManagerNativeLibrary.(Unknown Source)
    at sun.font.SunFontManager$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Unknown Source)
    at sun.font.SunFontManager.(Unknown Source)
    ... 83 more

```

  • 写回答

4条回答 默认 最新

  • 叫兽-郭老师 Java领域新星创作者 2024-01-31 08:43
    关注

    参考通义千问和郭老师的小迷弟雅思莫了-编写提供,主要是为了帮助您快速解决问题,如下回答,您可以参考下,如有问题,评论区留言。

    这个问题是由于在Linux环境中运行Java应用时,缺少libfreetype.so.6这个库文件导致的。虽然你提到已经找到了这个库文件,但Docker容器可能并没有正确识别或链接到它。

    解决方法如下:

    1. 确保在你的Dockerfile中包含了安装freetype库的相关命令,例如对于基于Debian或者Ubuntu的镜像,你可以添加以下命令:

      RUN apt-get update && apt-get install -y libfreetype6
      
    2. 如果库文件已经在镜像中,但Java无法找到,那么可能是环境变量LD_LIBRARY_PATH没有包含该库文件的路径。你需要将库文件所在目录添加到LD_LIBRARY_PATH中。例如,在启动容器时设置环境变量:

      docker run -e LD_LIBRARY_PATH=/path/to/libfreetype.so.6:/other/path ...
      
    3. 或者,如果希望在全局范围内解决问题,可以将libfreetype.so.6链接到系统默认的库文件搜索路径如 /usr/local/lib/usr/lib 下:

      ln -s /path/to/libfreetype.so.6 /usr/local/lib/libfreetype.so.6
      

    请根据实际情况选择合适的方法来解决此问题。

    评论

报告相同问题?

问题事件

  • 创建了问题 1月31日

悬赏问题

  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振