You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't run a groovy script in powershell (May apply to some java scripts as well) #1849
If you run "jbang hello.groovy" in a powershell window you will see this error:
Error: Could not find or load main class .grape.enable=false
Caused by: java.lang.ClassNotFoundException: /grape/enable=false
The groovy script runner sets an option -Dgroovy.grape.enable=false to disable grape, however powershell treats the = specially.
I don't use other -D= options, but I assume they might cause problems as well.
I'm almost certain the same thing would happen if you passed a -D parameter to Java using the //JAVA-OPTIONS or //JAVAC-OPTIONS in Powershell.
I think the fix is to put quotes around any options containing equals signs when running in powershell.
Workaround? Use CMD or bash for now, but since windows is moving away from cmd towards powershell I expect you'll see this more often.
Fall on the same error.
Had to put double-quotes to run :
java.exe -D"groovy.grape.enable"=false -classpath 'C:\Users\myself.jbang\cache\jars\essai_groovy.groovy.9c8ab994d36a50f563de8e8475de7a4e4b20a0eb72f947362facd9f04c7bce16\essai_groovy.jar;C:\Users\myself.m2\repository\org\apache\groovy\groovy\4.0.14\groovy-4.0.14.jar' Main
Maybe just putting double-quotes arround groovy.grape.enable could solve the issue :
List gopts = Collections.singletonList("-D\"groovy.grape.enable\"=false");
in jbang/src/main/java/dev/jbang/source/sources/GroovySource.java
thanks for the detailed report! verified end to end on a windows 11 vm (Windows PowerShell 5.1.26100) against current main - this is fixed:
jbang hello.groovy runs fine in powershell; the script sees groovy.grape.enable=false, so the -D arrives intact instead of becoming ClassNotFoundException: /grape/enable=false
the root cause was real: powershell splits an unquoted -Dfoo.bar=baz at the dot (reproduced with a bare java.exe call). jbang's escaper quotes any dotted -D for powershell nowadays, which is exactly the fix you suggested
also verified the trickiest path: the command jbang emits gets re-parsed via Invoke-Expression in jbang.ps1, and the quoting survives that second parse too. the exact string executed was 'java.exe' '-Dfoo.bar=baz' '-Dspace.val=hello world' -Dplain=1 -classpath ... propcheck 'a b' and all properties and the spaced argument arrived intact (covers the 'may apply to java scripts as well' part - //RUNTIME_OPTIONS and //JAVA_OPTIONS go through this)
one narrow edge remains that quoting can't fix: a colon in a property name (-Dfoo:bar=baz) gets dropped by powershell even when quoted - practically unheard of for java properties, so not keeping this open for it. closing - please verify and open a new issue if anything still misbehaves on your setup.
Activity
quintesse commentedon Sep 12, 2024
(oh how I hate dealing with command line parsing on Windows!)
Mmagoo95 commentedon Mar 16, 2025
Fall on the same error.
Had to put double-quotes to run :
java.exe -D"groovy.grape.enable"=false -classpath 'C:\Users\myself.jbang\cache\jars\essai_groovy.groovy.9c8ab994d36a50f563de8e8475de7a4e4b20a0eb72f947362facd9f04c7bce16\essai_groovy.jar;C:\Users\myself.m2\repository\org\apache\groovy\groovy\4.0.14\groovy-4.0.14.jar' Main
Maybe just putting double-quotes arround groovy.grape.enable could solve the issue :
List gopts = Collections.singletonList("-D\"groovy.grape.enable\"=false");
in jbang/src/main/java/dev/jbang/source/sources/GroovySource.java
maxandersen-agent commentedon Dec 4, 2026
thanks for the detailed report! verified end to end on a windows 11 vm (Windows PowerShell 5.1.26100) against current main - this is fixed:
jbang hello.groovyruns fine in powershell; the script seesgroovy.grape.enable=false, so the -D arrives intact instead of becomingClassNotFoundException: /grape/enable=false-Dfoo.bar=bazat the dot (reproduced with a barejava.execall). jbang's escaper quotes any dotted -D for powershell nowadays, which is exactly the fix you suggestedInvoke-Expressionin jbang.ps1, and the quoting survives that second parse too. the exact string executed was'java.exe' '-Dfoo.bar=baz' '-Dspace.val=hello world' -Dplain=1 -classpath ... propcheck 'a b'and all properties and the spaced argument arrived intact (covers the 'may apply to java scripts as well' part - //RUNTIME_OPTIONS and //JAVA_OPTIONS go through this)one narrow edge remains that quoting can't fix: a colon in a property name (
-Dfoo:bar=baz) gets dropped by powershell even when quoted - practically unheard of for java properties, so not keeping this open for it. closing - please verify and open a new issue if anything still misbehaves on your setup.