简体   繁体   中英

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?

这是 .jar 的导出设置

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?).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM