javaexecutable-jarjava-9eclipse-oxygenapache-commons-lang

Java 9 JRE causes java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils on jar execution


I created a jar file on Eclipse Oxygen.1a (OS:Windows 10 Home edition 64-bit). My project's JRE is jre1.8.0_152(64-bit version). When I run my jar file using the Java 8 JRE, program works perfectly but when I use the Java 9 JRE I get the following error:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils

This error occurs when I execute: java -jar myjarfile.jar using Java 9 JRE .

I embedded the latest version of Apache Commons Lang (added commons-lang3-3.7.jar in project libraries) and used the latest Java 9 Runtime (jre9.0.1). Apache page states that Java 7.0+ is required.
Is there an incompatibility issue between Java 9 and Apache Commons libs? Any way to solve this?

Update:
Command line contains (Debug view, right-click on and click Properties)

"C:\Program Files\Java\jre1.8.0_152\bin\javaw.exe" 
-agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:50317 
-Dfile.encoding=UTF-8 
-classpath "C:\Program Files\Java\jre1.8.0_152\lib\resources.jar;
C:\Program Files\Java\jre1.8.0_152\lib\rt.jar;
C:\Program Files\Java\jre1.8.0_152\lib\jsse.jar;
C:\Program Files\Java\jre1.8.0_152\lib\jce.jar;
C:\Program Files\Java\jre1.8.0_152\lib\charsets.jar;
C:\Program Files\Java\jre1.8.0_152\lib\jfr.jar;
C:\Program Files\Java\jre1.8.0_152\lib\ext\access-bridge-64.jar;
C:\Program Files\Java\jre1.8.0_152\lib\ext\cldrdata.jar;
C:\Program Files\Java\jre1.8.0_152\lib\ext\dnsns.jar;
C:\Program Files\Java\jre1.8.0_152\lib\ext\jaccess.jar;
C:\Program Files\Java\jre1.8.0_152\lib\ext\jfxrt.jar;
C:\Program Files\Java\jre1.8.0_152\lib\ext\localedata.jar;
C:\Program Files\Java\jre1.8.0_152\lib\ext\nashorn.jar;
C:\Program Files\Java\jre1.8.0_152\lib\ext\sunec.jar;
C:\Program Files\Java\jre1.8.0_152\lib\ext\sunjce_provider.jar;
C:\Program Files\Java\jre1.8.0_152\lib\ext\sunmscapi.jar;
C:\Program Files\Java\jre1.8.0_152\lib\ext\sunpkcs11.jar;
C:\Program Files\Java\jre1.8.0_152\lib\ext\zipfs.jar;
C:\my Java lab\Eclipse Oxygen\Workspaces\JNotifier\JNotifier\bin;
C:\my Java lab\Eclipse Oxygen\Workspaces\JNotifier\JNotifier\src\libPack\commons-lang3-3.7.jar" libPack.JCostCalculator

Jar file created by exporting a Runnable JAR with Eclipse, using these settings:
Runnable JAR export settings

Second update: I tested my JAR on an other Windows 10 pro 64-bit system and on Ubuntu 16.04.3 LTS with Java 9 and had the same problem.


Solution

  • Solution finally found after careful consideration of user comments. Problem solved when I selected "Extract required libraries into generated JAR" instead of Package them. enter image description here Now my jar file work fine with Java 8 and Java 9 JRE. Tested it on my Linux and Windows stations (32 and 64 bit).

    I believe the core of the problem was that Java 9 JRE wasn't able to detect Apache Commons Lang library in JAR form (commons-lang3-3.7.jar). When the contents of commons-lang3-3.7.jar where extracted into my JAR, problem solved!