title: Generating Apache POI xlsx file with Spring Boot Java in Docker
body: <p>I have app that generates PDF with iTextPdf and now I have added Apache POI to generate Excel file on the same data. Front is JS with jQuery and backend is Java 11 (openJDK) with Spring Boot, Apache POI 5.0.
  The problem is that everything works fine while running in IDE. File is generated and downloads with no problems. The problem occurs when I run apps docker container. If I try to generate Excel file I get error: <code>java.io.IOException: org.apache.poi.ooxml.POIXMLException: java.lang.reflect.InvocationTargetException</code>with no &quot;Caused by&quot;.
  I use ByteArrayOutputStream and OutputStream to generate xlsx file and download it in browser. I don't try to store file in some folder and I don't use Docker volumes. Maybe Apache POI uses some temp folder while generating file? And it can't do this while runs from Docker?</p>
  <p>Thanks in advance.</p>
  <p>Controller:</p>
  <pre><code>try {
      Workbook workbook = excelGenerators.getExcelWorkbook(filteredList);
  
      ByteArrayOutputStream boas = new ByteArrayOutputStream();
  
      try {
          workbook.write(boas);
      } finally {
          boas.close();
      }
  
      response.setHeader(&quot;Expires&quot;, &quot;0&quot;);
      response.setHeader(&quot;Cache-Control&quot;, &quot;must-revalidate, post-check=0, pre-check=0&quot;);
      response.setHeader(&quot;Pragma&quot;, &quot;public&quot;);
      response.setContentType(&quot;application/vnd.ms-excel&quot;);
      response.setHeader(&quot;Content-disposition&quot;,&quot;attachment; filename=report.xlsx&quot;);
      response.setContentLength(boas.size());
      
      OutputStream os = response.getOutputStream();
      boas.writeTo(os);
      os.flush();
      os.close();
  } catch (Exception e) {
      throw new IOException(e.getMessage());
  }
  </code></pre>
  <p>ExcelGenerator:</p>
  <pre><code>public Workbook getExcelWorkbook(List&lt;FullOrder&gt; orderList) {
          XSSFWorkbook workbook = new XSSFWorkbook();
  
          Sheet sheet = workbook.createSheet(&quot;SHEET ONE&quot;);
          sheet.createFreezePane(0, 1);
          sheet.setColumnWidth(0, 16000);
          ...
  
          CellStyle headerStyle = sheet.getWorkbook().createCellStyle();
          headerStyle.setFillForegroundColor(IndexedColors.AQUA.index);
          headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
          headerStyle.setAlignment(HorizontalAlignment.CENTER);
  
          XSSFFont font = workbook.createFont();
          font.setFontName(&quot;Arial&quot;);
          font.setFontHeightInPoints((short) 12);
          font.setBold(true);
          headerStyle.setFont(font);
  
          Row header = sheet.createRow(0);
  
          Cell headerCell = header.createCell(0);
          headerCell.setCellValue(&quot;Klientas&quot;);
          headerCell.setCellStyle(headerStyle);
  
          ... 
  
          CellStyle singleOrderCellStyle = workbook.createCellStyle();
          singleOrderCellStyle.setWrapText(true);
          singleOrderCellStyle.setAlignment(HorizontalAlignment.LEFT);
  
          AtomicInteger rowCount = new AtomicInteger(1);
  
          orderList.forEach(order -&gt; {
              Row row = sheet.createRow(rowCount.get());
  
              Cell cell = row.createCell(0);
              cell.setCellValue(order.getClient().getLabel());
              cell.setCellStyle(singleOrderCellStyle);
  
              ...
  
              rowCount.getAndIncrement();
          });
  
          CellStyle totalStyle = sheet.getWorkbook().createCellStyle();
          totalStyle.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.index);
          totalStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
          totalStyle.setAlignment(HorizontalAlignment.CENTER);
  
          XSSFFont fontTotal = workbook.createFont();
          fontTotal.setFontName(&quot;Arial&quot;);
          fontTotal.setFontHeightInPoints((short) 12);
          fontTotal.setBold(true);
          totalStyle.setFont(fontTotal);
  
          Row totalRow = sheet.createRow(rowCount.get());
  
          Cell cell = totalRow.createCell(0);
          cell = totalRow.createCell(1);
          cell = totalRow.createCell(2);
  
  
          cell = totalRow.createCell(3);
          cell.setCellValue(totalCount[0]);
          cell.setCellStyle(totalStyle);
  
          cell = totalRow.createCell(4);
          cell = totalRow.createCell(5);
  
          cell.setCellValue(Double.parseDouble(decimalFormat.format(totalSum[0]).replace(',', '.')));
          cell.setCellStyle(totalStyle);
  
          return workbook;
      }
  </code></pre>
  <p>I have changed catch with <code>logger.error(e.getClass() + &quot;: &quot; +  e.getMessage() + &quot;: &quot; + e.getCause(), e);</code> and now stack trace looks like this:</p>
  <pre><code>2021-05-17 12:09:34.060 ERROR 1 --- [io-8080-exec-10] c.s.l.controller.ManagementController    : class org.apache.poi.ooxml.POIXMLException: org.apache.poi.ooxml.POIXMLException: java.lang.reflect.InvocationTargetException: org.apache.poi.ooxml.POIXMLException: java.lang.reflect.InvocationTargetException
  ...
  Caused by: org.apache.poi.ooxml.POIXMLException: java.lang.reflect.InvocationTargetException
      at org.apache.poi.ooxml.POIXMLFactory.newDocumentPart(POIXMLFactory.java:111) ~[poi-ooxml-4.0.1.jar:4.0.1]
      at org.apache.poi.ooxml.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:588) ~[poi-ooxml-4.0.1.jar:4.0.1]
      ... 95 common frames omitted
  Caused by: java.lang.reflect.InvocationTargetException: null
      at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
      at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
      at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
      at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
      at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:56) ~[poi-ooxml-4.0.1.jar:4.0.1]
      at org.apache.poi.ooxml.POIXMLFactory.newDocumentPart(POIXMLFactory.java:109) ~[poi-ooxml-4.0.1.jar:4.0.1]
      ... 96 common frames omitted
  Caused by: java.lang.NoSuchMethodError: org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont.addNewFamily()Lorg/openxmlformats/schemas/spreadsheetml/x2006/main/CTIntProperty;
      at org.apache.poi.xssf.usermodel.XSSFFont.setFamily(XSSFFont.java:602) ~[poi-ooxml-4.0.1.jar:4.0.1]
      at org.apache.poi.xssf.usermodel.XSSFFont.setFamily(XSSFFont.java:614) ~[poi-ooxml-4.0.1.jar:4.0.1]
      at org.apache.poi.xssf.model.StylesTable.createDefaultFont(StylesTable.java:765) ~[poi-ooxml-4.0.1.jar:4.0.1]
      at org.apache.poi.xssf.model.StylesTable.initialize(StylesTable.java:716) ~[poi-ooxml-4.0.1.jar:4.0.1]
      at org.apache.poi.xssf.model.StylesTable.&lt;init&gt;(StylesTable.java:130) ~[poi-ooxml-4.0.1.jar:4.0.1]
      ... 102 common frames omitted
  </code></pre>
  <p>After adding or changing jars related to apache poi to version 3.17 I get another error:</p>
  <pre><code>java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.xssf.model.SharedStringsTable
  </code></pre>