Search code examples
javajarnosuchmethoderror

Java NoSuchMethodError for regex.Matcher.results() when running .jar file


When I run my app as a .jar file, it returns the below error:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrc
der.java:61)
Caused by: java.lang.NoSuchMethodError: java.util.regex.Matcher.results()Ljav
til/stream/Stream;
        at SalesToExcel.start(SalesToExcel.java:108)
        at SalesToExcel.main(SalesToExcel.java:45)
        ... 5 more

However, it works when I run it inside of the Eclipse IDE. Any ideas? I'm not sure if I'm somehow missing a proper jar file even though java.utils.regex should come included in rt.jar. Is there a way to check if this is missing somehow when I package the jar?

Here are the export settings to .jar


Solution

  • So, this is your problem. java.util.regex.Matcher.results is in Java since Java 9 and you are running the .jar with Java 8.

    Eclipse runs with Java11.

    Install as default JRE at least Java9 in your OS (Windows ?).