5 Replies Latest reply on Dec 4, 2015 3:49 PM by George Berish

    Is it possible to use System Environment Variables in a command executed from the JBoss CLI?

    George Berish Novice

      When working from Windows Command Prompt I can use System Environment Variables.

       

      For example:

      C:\>echo %WILDFLY_HOME%

      D:\Bulletproof\bpWildFly

       

      But when I start jboss-cli.bat, and then try to access the variable name from the jboss command line I can't:

       

      For example

       

      [standalone@localhost:9990 /] echo $WILDFLY_HOME

      Unrecognized variable WILDFLY_HOME

       

      Does that mean  I can't use System Variables in a command executed from JBoss CLI?

      Or does in mean I'm doing it wrong?

       

      I ask because I'd really like to execute a command like this one

      [standalone@localhost:9990 /] module add --name=com.mysql.driver --dependencies=javax.api,javax.transaction.api --resources=<type  in  a  really  long  path  here>\mysql-connector-java-5.1.35.jar

       

      using something like

      [standalone@localhost:9990 /] module add --name=com.mysql.driver --dependencies=javax.api,javax.transaction.api --resources=$MY_STUFF\mysql-connector-java-5.1.35.jar

       

      Can anyone help?

        • 1. Re: Is it possible to use System Environment Variables in a command executed from the JBoss CLI?
          Jay SenSharma Master

          You can try the following:

          Option-1).  Passing custom system properties using -D option

          ./jboss-cli.sh -c -Daaa.bbb=ccc  -DWILDFLY_HOME=/PATH/TO/wildfly-10.0.0.CR3-SNAPSHOT
          
          [standalone@localhost:9990 /] echo ${WILDFLY_HOME}
          /Users/jsensharma/NotBackedUp/Installed/wildfly-10.0.0.CR3-SNAPSHOT
          
          [standalone@localhost:9990 /] echo ${aaa.bbb}
          ccc
          
          
          [standalone@localhost:9990 /] echo ${user.dir}
          /PATH/TO/wildfly-10.0.0.CR3-SNAPSHOT/bin
          
          [standalone@localhost:9990 /] echo ${user.name}
          jsensharma
          
          
          
          
          

           

          But in order to do that you will need to edit the following file "$JBOSS_HOME/bin/jboss-cli.xml" and will need to ser the following property to "true"  (by default that is false)

           

              <!-- whether to resolve system properties specified as command argument or operation parameter values
                            in the CLI VM before sending the operation requests to the controller -->
              <resolve-parameter-values>true</resolve-parameter-values>
          
          
          
          
          

           

           

          Option-2)  Write your own Bat file which will first set some variables by reading the Environment values and in the same BAT file invoke the jboss-cli.cmd script by passing those values.

           

          set wildfly_home=%WILDFLY_HOME%_set aaa.bbb=ccc
          set MY_STUFF=C:\somedir\containing\the\jars
          
          %WILDFLY_HOME%\bin\jboss-cli.cmd -c
          batch
          echo ${wildfly_home}
          module add --name=com.mysql.driver --dependencies=javax.api,javax.transaction.api --resources=${MY_STUFF}\mysql-connector-java-5.1.35.jar
          /////// Write further commands here......
          run-batch
          exit
          
          
          
          

           

           

           

          Additionally you can also have a look at the :  Command line environment variables   which explains how to declare custom variables while using jboss-cli and how to use the.     Also how to pass properties file containing some pre defined properties using "--properties" as described in :

           

          Regards

          Jay SenSharma

          • 2. Re: Is it possible to use System Environment Variables in a command executed from the JBoss CLI?
            Tomaz Cerar Master

            to access environment variables, as you want to.

            proper syntax would be ${env.WILDFLY_HOME} in your case.

             

            so just prefix it with env., without that it looks for system properties as Jay noted above.

            • 3. Re: Is it possible to use System Environment Variables in a command executed from the JBoss CLI?
              George Berish Novice

              Tomaz,

               

              It must be me, but I can't make it work. [If there's a typo I can't see it.]

              I pasted the command window output below.

               

              -- The command window can read and echo the Environment Variable WILDFLY_BIN OK.

               

              -- It can also recognize it and use it in the change directory command OK.

               

              But ... once I start jboss-cli.bat, the jboss CLI doesn't recognize it.

               

              Maybe the CLI only sees variables it sets?

              -----------------------------------------------------------------

              Microsoft Windows [Version 6.1.7601]

              Copyright (c) 2009 Microsoft Corporation.  All rights reserved.


              D:\>echo %WILDFLY_BIN%     <Works>

              D:\Bulletproof\bpWildFly/bin

               

              D:\>cd %WILDFLY_BIN%     <Works>


              D:\Bulletproof\bpWildFly\bin>jboss-cli.bat


              You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.

              [disconnected /] connect


              [standalone@localhost:9990 /] echo ${env.WILDFLY_BIN}     <Fails>

              ${env.WILDFLY_BIN}

               

              [standalone@localhost:9990 /]

               

              • 4. Re: Is it possible to use System Environment Variables in a command executed from the JBoss CLI?
                Jay SenSharma Master

                Which version of WildFLy are you using?  is it WildFly 8 ?

                 

                I tried it on WildFly 9 and Wildfly 10 as following and it works:

                 

                [disconnected /] echo ${env.JBOSS_HOME}
                /Users/jsensharma/NotBackedUp/Installed/wildfly-9.0.1.Final
                
                AND
                
                [disconnected /] echo ${env.JBOSS_HOME}
                /Users/jsensharma/NotBackedUp/Installed/wildfly-10.0.0.CR3-SNAPSHOT
                

                 


                NOTE: But in order to do that you will need to edit the following file "$JBOSS_HOME/bin/jboss-cli.xml" and will need to ser the following property to "true"  (by default that is false)

                 

                    <!-- whether to resolve system properties specified as command argument or operation parameter values 
                                  in the CLI VM before sending the operation requests to the controller --> 
                    <resolve-parameter-values>true</resolve-parameter-values> 
                
                • 5. Re: Is it possible to use System Environment Variables in a command executed from the JBoss CLI?
                  George Berish Novice

                  Jay,

                   

                  I'm on Wildfly 8.

                  Changed value in jboss-cli.xml to true.

                  Now works perfectly. You sure seem to have WildFly mastered. Thanx.

                   

                  Here's command window ouput:

                   

                  Microsoft Windows [Version 6.1.7601]

                  Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

                  D:\>cd %WILDFLY_BIN%

                  D:\Bulletproof\bpWildFly\bin>jboss-cli.bat

                  You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.

                  [disconnected /] connect


                  [standalone@localhost:9990 /] echo ${env.WILDFLY_BIN}

                  D:BulletproofbpWildFly/bin


                  [standalone@localhost:9990 /]


                  Minor Point:  Please note that when Wildfly echoed the variable it left off the "/"  between directories.  So I went back to command window, exited the CLI and tried again, and it is definitely the CLI, because in the comand window the echo was correct.  I'll have to try it in a CLI command to see if its just a printing problem or the "/" gets lost.

                   

                  FOUND IT.  The command window seems happy with either "/" or "\" even when you mix them in one variable as I foolishly did. 

                  BUT ... Wildfly only see "/" and ignores "\".  Once I corrected my error ${env.WILDFLY_BIN} worked perfectly.


                  This is an example of what happened when I still had "\" in my variable string.  Once I made all slashes "/" all worked as expected.

                  Continuation of command window output.

                   

                  [standalone@localhost:9990 /] echo ${env.WILDFLY_BIN}

                  D:BulletproofbpWildFly/bin

                  [standalone@localhost:9990 /] exit

                   

                  Press any key to continue . . .

                   

                  D:\Bulletproof\bpWildFly\bin>echo %WILDFLY_BIN%

                  D:\Bulletproof\bpWildFly/bin <------------note mixed use of "/" and "\"

                   

                  D:\Bulletproof\bpWildFly\bin>

                  1 of 1 people found this helpful