Search code examples
javabatch-filejava-8java-native-interfaceapache-poi

JNI Error with Java1.8.0_112 and Apache POI


I have just installed Java1.8.0_112, both jdk and jre 64bit on my Windows 7 machine.

I am attempting to run one of my programs via a .bat file and am getting the following error:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/use
rmodel/Workbook
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.privateGetMethodRecursive(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 7 more

I have uninstalled and reinstalled the jre and I have restarted my machine. I have made sure I am pointing to all the libraries needed.

What really baffles me is that this error is showing about the POI workbook, but I have all the apache libraries I need and their appropriate dependencies so I'm not sure why this is an issue. Like I said, runs like a charm in Netbeans on the jdk, but completely implodes when I run it on my desktop via .bat

The program runs just fine in the Netbeans8 environment, which is using the jdk of 1.8.0_112 and the JDK8 binary.

My .bat file is as follows, I've added line breaks for readability:

C:\jre1.8.0_112\bin\java -cp 
"T:\Netbeans Projects\MatchReport\build\classes;
S:\ADSJava\Jars\lib\poi-3.15.jar;
S:\ADSJava\Jars\lib\poi-ooxml-3.15.jar;
S:\ADSJava\Jars\lib\poi-ooxml-schemas-3.15.jar;
C:\Users\Jessica\Desktop\lib\xmlbeans-2.6.0.jar;
S:\ADSJava\Jars\lib\dom4j-1.6.1.jar;
S:\ADSJava\Jars\lib\commons-io-2.5.jar;
S:\ADSJava\Jars\lib\junit-4.12.jar;
S:\ADSJava\Jars\lib\commons-codes-1.10.jar;
S:\ADSJava\Jars\lib\commons-collections4-4.1.jar;
C:\Users\Jessica\Desktop\lib\DataServer.jar;
C:\Users\Jessica\Desktop\lib\ucanaccess-3.0.4.jar;
C:\Users\Jessica\Desktop\lib\jackcess-2.1.3.jar;
C:\Users\Jessica\Desktop\lib\xbeans.jar;
C:\Users\Jessica\Desktop\lib\commons-logging-1.0.4.jar;
C:\Users\Jessica\Desktop\lib\hsqldb.jar;
C:\Users\Jessica\Desktop\lib\commons-lang-2.4.jar" 
ads.ADSMatchReport2 
"Toyota Of Turnersville Control.txt" 2>&1> MatchReportResults.txt

Any help or guidance would be greatly appreciated, thank you!


Solution

  • Found the solution. The .bat file did not like me having libraries on mixed drives. Moving all the libraries to either my C: or the network S: drive solved the issue.

    For whatever reason Netbeans was able to handle libraries in multiple locations but the .bat file does not.