[英]how to run service with WildFly server by wildfly-maven-plugin?
[英]How to wait for the WildFly server to reload?
我按如下方式重新加載 WildFly 服務器
CliCommandBuilder cliCommandBuilder = ...
cliCommandBuilder
.setCommand(
"reload"
);
Launcher.of(cliCommandBuilder)
.inherit()
.setRedirectErrorStream(true)
.launch();
我需要等待服務器啟動,因為那時我將部署新內容。 我怎樣才能做到這一點?
我嘗試使用 java.lang.Process 中的方法java.lang.Process
.waitFor()
Launcher.of(cliCommandBuilder)
.inherit()
.setRedirectErrorStream(true)
.launch().waitFor();
但是線程在關閉WildFly后繼續工作,沒有啟動
我認為reload
命令會等到 WildFly 重新加載后才終止進程。 但是,您可以使用 助手 API來檢查該過程。 這樣的事情應該有效:
final CliCommandBuilder commandBuilder = CliCommandBuilder.of("/opt/wildfly-27.0.0.Final")
.setConnection("localhost:9990")
.setCommand("reload");
final Process process = Launcher.of(commandBuilder)
.inherit()
.setRedirectErrorStream(true)
.launch();
// Wait for the process to end
if (!process.waitFor(5, TimeUnit.SECONDS)) {
throw new RuntimeException("The CLI process failed to terminate");
}
try (ModelControllerClient client = ModelControllerClient.Factory.create("localhost", 9990)) {
while (!ServerHelper.isStandaloneRunning(client)) {
TimeUnit.MILLISECONDS.sleep(200L);
}
if (!Operations.isSuccessfulOutcome(result)) {
throw new RuntimeException("Failed to check state: " + Operations.getFailureDescription(result).asString());
}
System.out.printf("Running Mode: %s%n", Operations.readResult(result).asString());
}
您需要明確地將 CLI 連接到服務器。 默認情況下,這是localhost:9990
,您可以通過將connect
添加到 CLI 命令來訪問它(請參閱WildFly 管理指南)。 否則,您應該使用setController
方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.