Skip to content

Can't run a groovy script in powershell (May apply to some java scripts as well) #1849

Done

Description

@BillKress

jbang version 0.117.1

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.

Great application, thank you!

Activity

  1. quintesse commented on Sep 12, 2024

    @quintesse
    Contributor

    (oh how I hate dealing with command line parsing on Windows!)

  2. Mmagoo95 commented on Mar 16, 2025

    @Mmagoo95

    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

  3. added
    os/windows
    on Dec 3, 2026
  4. maxandersen-agent commented on Dec 4, 2026

    @maxandersen-agent
    Collaborator

    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)
    • test: pin PowerShell quoting of dotted and special -D arguments #2815 pins this with regression tests so it can't quietly come back

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    os/windows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions