1

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.

Zerthimon
  • 435
  • 1
  • 9
  • 19
  • 1
    **commons-lang3-3.7.jar** works fine on my side. Can you please do the following: 1) Run your application, 2) When it's terminated, open Debug View, right-click on and click Properties, 3) Copy everything from Command Line and paste here in the question. – ZhekaKozlov Nov 19 '17 at 13:43
  • *I created a jar file* do you mean using Eclipse? Could you share the steps followed by you? – Naman Nov 19 '17 at 13:50
  • @ZhekaKozlov I updated my post. Comments have a maximum number of characters. – Zerthimon Nov 19 '17 at 15:41
  • @nullpointer I updated my post with jar creation actions I made. – Zerthimon Nov 19 '17 at 15:43
  • 1
    @Zerthimon From your command line, it doesn't look like you are running from the JAR. Instead, you are running from the **bin** folder. – ZhekaKozlov Nov 19 '17 at 17:02
  • @ZhekaKozlov maybe my post isn't 100% clear. I'm getting the error outside Eclipse NOT inside when I compile/run my class. When I run from command prompt (Windows) or terminal (Linux): java - jar myjarfile.jar using the Java 9 JRE I always get that error. There is NO error with Java 8 JRE and my app works fine. – Zerthimon Nov 19 '17 at 23:10
  • @nullpointer Eclipse uses JRE not JDK. In any case I don't run my JAR file from Eclipse but as a Stand-Alone Runnable Application in Windows or Linux. – Zerthimon Nov 19 '17 at 23:17
  • If you mean you've created a jar using JRE8 in eclipse and now trying to run the jar using JDK9/bin/jar command, then make sure there are no conflicting dependencies in your project that resolves to StringUtils from commons3. Also, NoClassDefFoundError could be possible with incorrect packaging as well for which the details are not shared in the question, – Naman Nov 20 '17 at 01:25
  • 1
    @Zerthimon Does your JAR contain `org.apache` packages? Can you check it? You can just unpack it as a zip file. – ZhekaKozlov Nov 20 '17 at 04:14
  • @ZhekaKozlov your comment "generated" the solution. Java 9 JRE wants libraries inside JAR extracted not packed. Now upon unpack folder org (org.apache...) is visible instead of commons-lang3-3.7.jar. Thanks. – Zerthimon Nov 20 '17 at 07:02

1 Answers1

1

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!

Zerthimon
  • 435
  • 1
  • 9
  • 19
  • 2
    I doubt this a JDK 9 issue, it sounds more like Eclipse not putting commons-lang3.3.7.jar on the class path. It would be useful to try this outside of the Eclipse environment to see if you can duplicate the issue. – Alan Bateman Nov 20 '17 at 07:03
  • @AlanBateman Eclipse Oxygen launched with many issues with Java 9 so probably it is an Eclipse bug. I'll duplicate the issue using NetBeans IDE 8.2 and post the results. – Zerthimon Nov 20 '17 at 07:15
  • If you suspect an Eclipse bug, please report it at https://bugs.eclipse.org/bugs/enter_bug.cgi?product=JDT, TIA. – Stephan Herrmann Nov 20 '17 at 20:43
  • Your workaround indicates that probably class org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader is not fully functional on Java 9, so in case you report a bug please include the stack trace of the NCDFE, to see if that class is indeed involved. – Stephan Herrmann Nov 20 '17 at 20:54