0

Why do I get an error on this simple Groovy code snippet

String strFile = "data/test"
File aFile = new File(strFile);

aFile.eachLine { aLine ->
   println aLine;
}

The error is:

Caught: java.lang.NoClassDefFoundError: Unable to load class org.apache.groovy.jaxb.extensions.JaxbExtensions due to missing dependency javax/xml/bind/JAXBContext
java.lang.NoClassDefFoundError: Unable to load class org.apache.groovy.jaxb.extensions.JaxbExtensions due to missing dependency javax/xml/bind/JAXBContext
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

I'm using

groovy --version
Groovy Version: 3.0.7 JVM: 1.8.0_312 Vendor: Red Hat, Inc. OS: Linux

Searching for a solution I found that (I think) the syntax I'm using is correct:

I had a strange error on another question, and it turned out I was mixing unsupported versions of groovy and Java. See Groovy and Java support matrix, and http://groovy-lang.org/releasenotes/groovy-2.3.html#Groovy2.3releasenotes-OfficialsupportforrunningGroovyonJDK8 which says Groovy 2.3 supports JDK 8. So I'll try that to see if the problem goes away.

PatS
  • 8,833
  • 12
  • 57
  • 100
  • It's working fine for me, at least. https://i.stack.imgur.com/NpNAM.png. See if it works https://stackoverflow.com/a/54489085/10553411 – Ganesh Thorat May 04 '22 at 08:27
  • It looks like it has to do with unmet dependencies on libs in your build path that are unrelated to this snippet. What happens when you run just this snippet in Groovy Console ? – ou_ryperd May 04 '22 at 09:59

0 Answers0