1

Im trying to launch my .jar File on my Server from Vultr.com but every time I launch it an Error comes up.

    String excelFolder = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath().replace("heroesBot.jar", "");
    DataFormatter dataFormatter = new DataFormatter();


    try(InputStream inputStream = new FileInputStream(excelFolder + "Summon.xlsx")) {


        Workbook wb = WorkbookFactory.create(inputStream);
        Sheet sheet = wb.getSheetAt(0);
        wb.close();

The Line where I create the Workbook always causes the Error. Anything I can do about it?

The file size is 96KB

Here is the Error:

java.io.IOException: Java heap space
    at org.apache.poi.ss.usermodel.WorkbookFactory.createWorkbook(WorkbookFactory.java:353)
    at org.apache.poi.ss.usermodel.WorkbookFactory.createXSSFWorkbook(WorkbookFactory.java:316)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:234)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:200)
    at heroes.Section.createKeys(Section.java:33)
    at main.Main.main(Main.java:37)
Caused by: java.lang.OutOfMemoryError: Java heap space
    at java.base/java.util.regex.Matcher.<init>(Matcher.java:248)
    at java.base/java.util.regex.Pattern.matcher(Pattern.java:1133)
    at org.apache.poi.ss.util.CellReference.separateRefParts(CellReference.java:396)
    at org.apache.poi.ss.util.CellReference.<init>(CellReference.java:113)
    at org.apache.poi.xssf.usermodel.XSSFCell.<init>(XSSFCell.java:119)
    at org.apache.poi.xssf.usermodel.XSSFRow.<init>(XSSFRow.java:77)
    at org.apache.poi.xssf.usermodel.XSSFSheet.initRows(XSSFSheet.java:268)
    at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:231)
    at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:218)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.parseSheet(XSSFWorkbook.java:448)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:413)
    at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:184)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:282)
    at org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(XSSFWorkbookFactory.java:88)
Olaf Kock
  • 43,342
  • 7
  • 54
  • 84
  • How much memory is your application / server using? – mentallurg Feb 01 '20 at 23:14
  • The server has RAM of 1024 MB – Gamal Hassan Feb 01 '20 at 23:22
  • Can you link/upload the excel file having problem? And have you tried to read other excel file (same error exist)? – samabcde Feb 02 '20 at 15:15
  • Excelsheets can consume a lot of memory when read with POI. You may want to try reading from `File` directly, instead of using an `InputStream`, if that doesn't work, you will need to look at streaming the excelsheet instead of reading it entirely into memory. – Mark Rotteveel Feb 03 '20 at 09:49

1 Answers1

1

It is not important how much memory server has. Important is, how much memory you give your application (how much memory you allow your application to use). Try following command:

java -Xmx256M -jar your.jar

It means you allow the application to use 256 MB RAM. If it is not sufficient, use greater value.

Update

Based on stack trace, processing of a regular expression takes much memory. POI uses regular expressions extensively, e.g. to process cell references. May be your Excel sheet contains a formula with a cell reference that causes POI to consume much memory to process this regular expression. Check the formulas in your Excel sheet.

mentallurg
  • 4,271
  • 5
  • 22
  • 32