通过Wildfly本地管理api进行部署

时间:2015-12-18 10:05:28

标签: deployment wildfly wildfly-9

我尝试使用native management api在Wilfly 9上部署Web应用程序。在这种情况下,正确的请求如何?使用CLI时,命令为

$JBOSS_CLI --connect --command="deploy /path/to/war"

但它不符合operation request syntax的定义。我尝试使用请求进行部署

{
    "address" => [("deployment" => "/path/to/war")],
    "operation" => "deploy"
}

但收到错误回复:

{
    "outcome" => "failed",
    "failure-description" => "WFLYCTL0216: Management resource '[(\"deployment\" => \"/path/to/war\")]' not found",
    "rolled-back" => true
}

1 个答案:

答案 0 :(得分:0)

好的,这就是我想出的:

以下cli命令与deploy的结果相同,文件路径为参数: /deployment=my_deployment:add(enabled=true,content[url=file:///path/to/war]) 用Java翻译:

String address = ...
int port = ...
String user = ...
String pass = ...
Path file = ...
ModelNode request = new ModelNode();
request.get(ClientConstants.OP).set(ClientConstants.ADD);
request.get(ClientConstants.OP_ADDR).add("deployment", "my_deployment");
request.get("enabled").set(true);
request.get("content").add("url", file.toUri().toString());
try (ModelControllerClient conn = ModelControllerClient.Factory.create(address, port, new PasswordClientCallbackHandler(user, null, pass.toCharArray()))) {
    ModelNode response = conn.execute(request);
    Logger.getLogger(Test.class.getName()).info(response);
}