Use conditional statements in WildFly CLI

Published: 13 March 2018

WildFly Command Line Interfaceis not a real programming language with complex structures. Nevertheless it’s possible to execute conditional logic in it and this short tutorial will show how to do it.

WildFly Command Line Interfacecontains the “if” keywords which can be used to build conditional logic.

here is the synopsys of the command:

if (condition_expression) of (command_line)

The if
statement includes a command that is executed at the beginning of the if-else control flow. After the response of the command_line is received from the controller, it is evaluated using the condition_expression.

The condition_expression
consists of a node path, equals sign (‘==’) and a specific value. If the target value designated with the node path equals to the specified value, then the condition is met and the if block (which is a batch) is executed.

If the condition wasn’t met then the else
block, if present, would be executed.

For example, here is how you can execute a conditional deployment- e.g. to check if the application myproject.war is not already deployed:

if (outcome != success) of /deployment=myproject.war:read-resource   
     deploy myproject.war   

Another example, slightly more complex, will check if the com.mysql module has been already installed. The conditional execution will either install it (if not installed already) or just print a message (saying that it’s already installed):

if (outcome != success) of /core-service=module-loading/:list-resource-loader-paths(module=com.mysql)   
    module add --name=com.mysql --resources=mysql-connector-java-5.1.31-bin.jar --dependencies=javax.api,javax.transaction.api
    echo module com.mysql already installed

Finally, you can check also the return value of a particular node and execute conditional logic based on the value of it:

if (result.value==true) of /system-property=test:read-resource
JBoss application server tutorials稿源:JBoss application server tutorials (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Use conditional statements in WildFly CLI

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录