我使用了docker做了一个很基础的Linux镜像,然后JDK是openjdk version "9.0.4",easyexcel的版本是3.1.0,我的代码在docker中运行上传的时候会报错,错误信息如下: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager 我根据官网给的例子的地址写的 DEMO代码地址:https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java 我把easyexcel版本换成3.3.2以后测试文件下载接口会出现新的异常: java.lang.UnsatisfiedLinkError: /opt/java/jdk-9.0.4/lib/libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory 这个是因为我的docker镜像里面缺少了什么东西吗?还是说JDK的问题呢?
[alibaba/easyexcel]openjdk version "9.0.4"会出现异常
回答
解决了吗 我的时遇到了java.lang.UnsatisfiedLinkError: /usr/local/jdk-1.8.0.352/jre/lib/amd64/libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory
你这个看着是jdk版本的问题,没有libfontmanager这个库,你可以参考下这个博客: https://www.cnblogs.com/suhai/p/14762756.html 我是直接换了一种下载接口的写法,excel下载的时候不使用easyexcel public void download(HttpServletResponse response) throws IOException { try (ServletOutputStream outputStream = response.getOutputStream()) { response.setContentType("application/octet-stream"); response.setCharacterEncoding("UTF-8"); String fileName = "Test"; response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xls"); smartExcelDwLog.generateExcel(outputStream, "XXX模板"); } catch (IOException e) { response.setHeader("Content-type", "text/html;charset=UTF-8"); OutputStream ps = response.getOutputStream(); ps.write("文件下载失败".getBytes(StandardCharsets.UTF_8)); ps.flush(); ps.close(); } }