1

I have seen other questions on this but the vast majority of answers specify setting dependencies POM.xml files i.e. for running groovy scripts in e.g. Intellij. I am simply trying to get groovyconsole (in windows) to execute a one line print command but despite trying various permutations of setting JAVA_OPTS nothing is working. When I set JAVA_OPTS the groovyconsole completely fails to launch.

groovyconsole

My java version is jdk 11, my groovy version is 3.0. I thought all this was supposed to have been solved back in groovy 2.6 or thereabouts.

C:\Users\J\Documents\Development>java -version
java version "11.0.5" 2019-10-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.5+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode)

C:\Users\J\Documents\Development>javac -version
javac 11.0.5

C:\Users\J\Documents\Development>echo %JAVA_HOME%
C:\Program Files\Java\jdk-11.0.5    

C:\Users\J\Documents\Development>groovy --version
Groovy Version: 3.0.0-beta-3 JVM: 11.0.5 Vendor: Oracle Corporation OS: Windows 10

If you refer me to another question please do ensure that there is an answer there that actually solves this particular issue because despite trawling through them I cannot find an answer for running just groovyconsole with Java 11. I repeat this question concerns running groovyconsole alone, not any groovy stuff in intellij.

I have tried setting JAVA_OPTS on the command line (eg set JAVA_OPTS=--add-modules java.xml.bind); I have tried supplying JAVA_OPTS when invoking groovyconsole (eg groovyconsole -DJAVA_OPTS=--add-modules java.xml.bind). When I do this groovyconsole simply fails to launch. Or perhaps it does launch but terminates before I can even see the window launching.

I have also tried the same with _JAVA_OPTS but that makes no difference; it's as if it's not even used/read when launching groovyconsole.

I am at the point now where I have spent hours and hours on this issue which really is quite ridiculous so it's time to ask for help.

Edit I have also just tried the following, both of which 'allow' the groovyconsole to launch but neither of which fixes the issue

C:\Users\J\Documents\Development>groovyconsole -D"JAVA_OPTS=--add-modules ALL-SYSTEM"
C:\Users\J\Documents\Development>groovyconsole -D"JAVA_OPTS=--add-modules java.xml.bind"

Edit I have also just tried the following, and they both prevent the console from launching at all:

C:\Users\J\Documents\Development>set JAVA_OPTS="--add-modules java.xml.bind"
C:\Users\J\Documents\Development>set JAVA_OPTS="--add-modules ALL-SYSTEM"
JL_SO
  • 1,742
  • 1
  • 25
  • 38
  • I just upgraded to Java 11, Groovy 2.5.8, and I am seeing the same thing. Underneath GROOVY_HOME/lib there are JAXB libraries, and the groovy-starter.conf file in the conf directory appears to put them on the classpath, so I don't know why it's broken. Did you ever find a fix? – Ken DeLong Nov 22 '19 at 18:39
  • Hi Ken, no I did not. But I suspect it's to do with a conflict between installed Java versions. – JL_SO Nov 25 '19 at 22:05
  • 1
    `--add-modules java.xml.bind` is not appropriate for Java 11 since it has deleted that module. I would use `set DEBUG=true` and see what is actually happening on your machine. `startGroovy.bat` (called by `groovyConsole.bat`) should be adding `-Dgroovy.jaxb=jaxb` to `JAVA_OPTS` which is then used by `groovy-starter.conf`. You could check you haven't created a custom version of that conf file on your classpath. – Paul King Nov 26 '19 at 03:21

1 Answers1

1

There's a bug about this filed in the Groovy JIRA, but it was closed https://issues.apache.org/jira/browse/GROOVY-9305 I found that if I moved the groovy-jaxb.jar file out of the lib dir, the console worked.

However, I note the font has changed (from 2.5.7 to 2.5.8) to a more janky looking fixed-width font. It makes me suspect something is still amiss. I use the groovyconsole a LOT so I'm a bit nervous...

EDIT I found out that I had a postInit.bat file in %HOME%/.groovy. This file had the line

SET JAVA_OPTS=-Xmx1g -Dgroovy.console.output.limit=200000

I had to change that to

SET JAVA_OPTS=%JAVA_OPTS% -Xmx1g -Dgroovy.console.output.limit=200000

because the startGroovy.bat file in %GROOVY_HOME%/bin adds the property -Dgroovy.jaxb=jaxb. My previous version of the file was erasing the JAVA_OPTS set by Groovy.

Ken DeLong
  • 929
  • 2
  • 8
  • 27