groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maarten Boekhold <>
Subject Disguise groovy script as windows batch file
Date Wed, 03 Jun 2015 10:05:13 GMT
Hi all,

Based on

The following works with groovy 2.1.8, but fails with 2.3.7 or 2.4.3:

    REM = /
    REM dummy groovy statement in first line and dummy groovy assignment
    to dummy string var rem
    C:\Maarten\local\groovy-2.1.8\bin\groovy "%~dp0%~nx0" %*
    interface ECHO {}
    // dummy groovy interface/annotation to make groovy interpreter
    ignore first line
    // start of script

    println "### Hello World from Groovy"

When I run this with groovy 2.3.7 or 2.4.3, I get:

    startup failed:
    C:\Maarten\tg.bat: 1: class ECHO is not an annotation in @ECHO
      @ line 1, column 1.
        @ECHO OFF

    1 error

Is there any way to make this work on recent versions of Groovy? The 
idea here is to have a groovy script that I can launch directly from a 
CMD prompt without needing to have groovy in the path, type "groovy 
thescript.groovy" or using a wrapper .bat file.

The definition of "interface ECHO {}" is there to make groovy ignore the 
first line of the file, by tricking it into thinking it is an annotation 
on the assignment to the REM variable.


View raw message