variablesescapingcommand-line-interfacewildflyoffline-mode

Using literal variables in a Wildfly OFFLINE CLI


I'd like to use an offline Wildfly CLI to add system properties

The problem is that the value should be a variable

This is the desired result:

        <property name="user.country" value="${country}"/>

the problem is that the CLI try to resolve the variable

[disconnected /] embed-server
[standalone@embedded /] /system-property=user.country:add(value="${country}")
{
    "outcome" => "failed",
    "failure-description" => "WFLYCTL0211: Cannot resolve expression '${country}'",
    "rolled-back" => true
}

I tried to escape the '$' with '$$' or '\$', but it doesn't worked.

Or rather, with '$$' I got

<property name="user.language" value="$${countrylowercase}"/>

If I run the server an retry with a connect CLI , it works normally.

How to do this offline?

As a workaround I'm doing a sed on the standalone to replace '$${' with '${', but it's not very clean...


Solution

  • The solution is to use a property file written like this:

    cat cli.property
    
        country=$country
        countrylowercase=$countrylowercase
    
    
    cat cli.commands
    
        embed-server 
        /system-property=user.language:add(value="${countrylowercase}") 
        /system-property=user.region:add(value="${country}") 
        /system-property=user.country:add(value="${country}") 
        stop-embedded-server 
    
    
    $JBOSS_HOME/bin/jboss-cli.sh --properties=./cli.property --file=./cli.commands
    
    {"outcome" => "success"}
    {"outcome" => "success"}
    {"outcome" => "success"}
    

    It's important to respect the syntax, because the following forma will also fail by using embedded mode

    cat cli.property
    
        country=${country}
        countrylowercase=${countrylowercase}