通过 Wildfly 本机管理部署 api

Deployment via Wildfly native management api

我正在尝试使用 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
}

好的,这是我想出的:

以下 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);
}