SourceForge has been redesigned. Learn more.
Close

error "unexpected char '\'" on Windows from Groovy script used in wrapper conf

Help
2014-02-21
2014-03-09
  • Brian Preuß

    Brian Preuß - 2014-02-21

    Hi,

    we have a own script file to start the wrapper:

    rem ##### Set JDK home, platform and architecture #####
    set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_51
    
    rem ##### Set locations #####
    set LOCATION=%~dp0..
    pushd %LOCATION%
    set LOCATION=%CD%
    popd
    set WRAPPER_HOME=%LOCATION%\server\wrapper
    
    rem ##### Set Wrapper configuration #####
    #set WRAPPER_CMD=%WRAPPER_HOME%\wrapper.exe
    set WRAPPER_CONF=%LOCATION%\etc\our-server.conf
    
    rem ##### Set command #####
    set COMMAND=
    set PROG_NAME=%~n0
    if /i "%PROG_NAME%" EQU "uninstall-our-server" ( set COMMAND=remove && goto :exec )
    if /i "%PROG_NAME%" EQU "install-our-server" ( set COMMAND=install && goto :exec )
    if "%1" == "" ( set COMMAND=console && goto :exec )
    for /f %%c in ('echo %1^|findstr "^console$ ^start$ ^stop$ ^restart$ ^install$ ^remove"') do ( set COMMAND=%%c && goto :exec )
    if not defined COMMAND (
        echo.
        echo Usage: %PROG_NAME% [ console ^| start ^| stop ^| restart ^| install ^| remove ]
        echo.
        pause
        goto :eof
    )
    
    rem ##### Start server with specified command #####
    :exec
    call :%COMMAND%
    goto :eof
    
    rem ##### Convert command to wrapper parameter #####
    :console
    call :exec-wrapper -c
    goto :eof
    
    :start
    call :exec-wrapper -tx
    goto :eof
    
    :stop
    call :exec-wrapper -px
    goto :eof
    
    :restart
    call :start && call :stop
    goto :eof
    
    :install
    call :exec-wrapper -i
    goto :eof
    
    :remove
    call :exec-wrapper -r
    goto :eof
    
    "%JAVA_HOME%\bin\java" -Xmx30m ^
        -Djna_tmpdir="%WRAPPER_HOME%\tmp" ^
        -DLOCATION="%LOCATION%" ^
        -DJAVA_HOME="%JAVA_HOME%" ^
        -DWRAPPER_HOME="%WRAPPER_HOME%" ^
        -jar "%WRAPPER_HOME%\wrapper.jar" ^
        %1 "%WRAPPER_CONF%"
    

    In our wrapper configuration file we have something like:

    wrapper.java.additional.11=${\
        if ("${os.name}".toLowerCase().contains("aix")) {\
            "-Xverbosegclog:${LOCATION}/log/gc/gc-server${new Date().format('yyyyMMddHHmmss')}.log"\
        } else {\
            "-Xloggc:${LOCATION}/log/gc/gc-server${new Date().format('yyyyMMddHHmmss')}.log"\
        }\
    }
    

    If we call our script with "our-server start" then we get the following error output:

    :C:\Users\brian\acme/log/gc/gc-server20140221133229.log"} else {"-Xloggc:C:\Use
    rs\brian\acme/log/gc/gc-server20140221133229.log"} : startup failed:
    Script5.groovy: 1: unexpected char: '\' @ line 1, column 67.
       ns("aix")) {"-Xverbosegclog:C:\Users\bri
                                     ^
    
    1 error
    

    Any hints how to remove the backslashes from the LOCATION variable? Maybe the wrapper ifself must replace the backslashes before evaluating the inline Groovy script?

    Regards,

    Brian

     
  • rzo

    rzo - 2014-02-22

    hello,

    in your configuration i see many "\" which is the escape character for configuration.
    i wonder if this is due to the sourceforge web site.
    could you pls either send me your configuration file, or add your configuration as an attachement, i would like to try and reproduce your issue.

    -- Ron

     
  • Brian Preuß

    Brian Preuß - 2014-02-24

    Hi Ron,

    please see the attached yajsw-post.conf. On Linux everything is fine, btw.

    Regards,

    Brian

     
  • rzo

    rzo - 2014-02-24

    hello,

    LOCATION probably contains "\"

    try the following:

    LOC=${new File("$LOCATION").absolutePath.replace(0x5C as char\, '/' as char)}

    and replace in the configuration file ${LOCATION} with ${LOC}

    -- Ron

     
  • Brian Preuß

    Brian Preuß - 2014-02-26

    Hi Ron,

    now I get

    error evaluating new File("C:\Users\imperia\pim").absolutePath.replace(0x5C as c
    har, '/' as char))/log/gc/gc-server20140226095441.log" : startup failed:
    Script4.groovy: 1: unexpected char: '\' @ line 1, column 13.
    new File("C:\Users\imperia\pim").absolutePath.replace(0x5C as char, '/' as ch
    ar))/log/gc/gc-server20140226095441.log"
    ^

    1 error

    I've already tried a similar approach before and got a similar error message like the above.

    Regards,

    Brian

     
    Last edit: Brian Preuß 2014-02-26
  • rzo

    rzo - 2014-02-26

    hello,

    in the configuration file one should write:

    new File("C:\\Users\\imperia\\pim")

    backslash is the escape char in commons configuration.

    -- Ron

     
  • Brian Preuß

    Brian Preuß - 2014-03-05

    Hi Ron,

    the file path is not hard coded in the configuration file. A variable called LOCATION is used in a Groovy scriplet in the configuration file. Somehow this variable get's replaced by it's value and Groovy complains about the backslash.

    Even the string replacement doesn't work.

    Seems to me the variable replacement needs to escape the value before inserting it into the Groovy scriptlet.

    Regards,

    Brian

     
  • rzo

    rzo - 2014-03-09

    Hello Brian,

    I tested the above and it works fine.
    I wonder what you are doing differently.
    As test I am running HelloWorld as described in the quick startup.
    The env var wrapper_home is set in setenv.bat, similarly to LOCATION in your case.

    in the configuration i am having:

    wrapper.working.dir=${new File("$wrapper_home").absolutePath.replace(0x5C as char\, '/' as char)}

    this is being used in further down in the configuration:

    wrapper.java.classpath.1 = ${wrapper.working.dir}/wrapper.jar

    i am testing with yajsw 11.11

    -- Ron

     
  • rzo

    rzo - 2014-03-09

    ps: sorry for the late reply, i am quit busy lately and i get to work on this mainly on weekends.

     

Log in to post a comment.