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.