0

Hello I am getting the following exception when running the jar. Can somebody help please?

U2007750s-MacBook-Pro:target u2007750$ java -jar ExcelCSVConverter-0.0.1-SNAPSHOT.jar
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Cell
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
        at java.lang.Class.getMethod0(Class.java:3018)
        at java.lang.Class.getMethod(Class.java:1784)
        at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
    Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Cell
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 7 more

UPDATE:

Until now I only had the poi-ooxml dependency in the pom.xml:

     <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.17</version>
    </dependency>

The program executes correctly in eclipse. It's only in the command line where the error occurs.

Now after recommendation of you guys, I have also added the second dependency poi:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.17</version>
</dependency> 

but still not success. Now the error occurs for this class:

U2007750s-MacBook-Pro:target u2007750$ java -jar ExcelCSVConverter-0.0.1-SNAPSHOT.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/impl/values/XmlValueOutOfRangeException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

The method is:

private static String getCellData(XSSFCell myCell) {
        String cellData = "";
        if (myCell == null) {
            cellData += CSV_SEPERATOR_CHAR;
        } else {
            try {
                switch (myCell.getCellTypeEnum()) {
                case STRING:
                case BOOLEAN:
                    cellData += myCell.getRichStringCellValue() + CSV_SEPERATOR_CHAR;
                    break;
                case NUMERIC:
                    cellData += getNumericValue(myCell);
                    break;
                case FORMULA:
                    cellData += getFormulaValue(myCell);
                default:
                    cellData += CSV_SEPERATOR_CHAR;
                }
            } catch (XmlValueOutOfRangeException e) {
                int a =2;
                //System.out.println("XmlValueOutOfRangeException for: "+ myCell.getRawValue());
                String rawValue = myCell.getRawValue();
                while(rawValue.startsWith("0")) {
                    rawValue = rawValue.substring(1);
                }
                cellData += rawValue+ CSV_SEPERATOR_CHAR;
            }
        }
        return cellData;
    }
farahm
  • 1,326
  • 6
  • 32
  • 70
  • 1
    Have you added the proper dependencies to the classpath? – XtremeBaumer Aug 27 '18 at 11:53
  • I have added dependency to pom.xml: org.apache.poi poi 3.17 – farahm Aug 27 '18 at 11:54
  • I'd agree with @XtremeBaumer OP : Check if all the dependencies are added - http://poi.apache.org/overview.html#components , you can always use maven or gradle for easiness, also check for the version - the latest is 3.17 – Wilfred Clement Aug 27 '18 at 11:55
  • You should go with [poi-ooxml](https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml/3.17) – XtremeBaumer Aug 27 '18 at 11:56
  • I have now added both: org.apache.poi poi 3.17 org.apache.poi poi-ooxml 3.17 but still same error – farahm Aug 27 '18 at 11:59
  • remove the normal `poi` dependency and also run a maven update on the project – XtremeBaumer Aug 27 '18 at 12:00
  • already tried that too, but still same error – farahm Aug 27 '18 at 12:01
  • Can you try importing the POI dependencies manually ? https://www.apache.org/dyn/closer.lua/poi/release/bin/poi-bin-3.17-20170915.zip Download the zip file from the above link and manually import all the JAR's inside – Wilfred Clement Aug 27 '18 at 12:03
  • Did you try ? it worked ? – Wilfred Clement Aug 27 '18 at 12:13
  • I have downloaded manually the poixml jar. Before that I was using HSSF. Now I am changing the code to XSSF. But for example now I am getting in the eclipse editor the following error: The type `org.apache.poi.ss.usermodel.CellType cannot be resolved. It is indirectly referenced from required .class files` – farahm Aug 27 '18 at 12:16
  • Ok now after also manually adding the poi jar. the editor erros are gone. Now im gonna create the jar again and lets see what happens now – farahm Aug 27 '18 at 12:19
  • Although the eclipse is not showing any error anymore. The terminal (commandline) says when I do `mvn package`: `package org.apache.poi.xssf.usermodel does not exist` , `package org.apache.poi.xssf.usermodel does not exist`, `cannot find symbol [ERROR] symbol: class XSSFCell` .... – farahm Aug 27 '18 at 12:22
  • well well, that is a compiler issue and I cannot tell you without checking the code. Check for this link - https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean - This isn't going to solve but can possibly help – Wilfred Clement Aug 27 '18 at 12:25
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/178858/discussion-between-wilfred-clement-and-farahm). – Wilfred Clement Aug 27 '18 at 12:26

1 Answers1

2

You need to download the following JAR files and add them to your build path.

Apache POI
Apache POI-OOXML

If you are using Maven:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.17</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.17</version>
</dependency>
<dependency>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
    <version>3.0.1</version>
</dependency>


And if you are using Graddle:

// https://mvnrepository.com/artifact/org.apache.poi/poi
compile group: 'org.apache.poi', name: 'poi', version: '3.17'
// https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
Ranielle Canlas
  • 624
  • 5
  • 19