2014-08-28 54 views
2

我能重啓JBoss AS 7.2.0最終使用JBoss CLI使用以下命令:重啓JBoss爲7編程

jboss-cli.bat --connect --controller=IP:9999 --command=:shutdown(restart=true) 

現在我需要從一個Java類編程做到這一點,我已經嘗試使用Jboss cli API,在我的代碼之後,但它只執行一個shutdonw並且不會重新啓動!

CommandContext ctx = null; 
try { 
    ctx = org.jboss.as.cli.CommandContextFactory.getInstance().newCommandContext(); 
    ctx.connectController(IP, 9999); 

    ctx.handle(":shutdown(restart=true)"); 

} catch (CommandLineException e) { 
    System.out.println(e.getMessage()); 
} 

有什麼想法嗎?

回答

3

確實沒有JBoss AS 7.2.0.Final,但我在WildFly 8和JBoss EAP 6.x上測試了以下內容,它對我很有幫助。請注意,端口9990用於WildFly,端口9999用於JBoss EAP 6.x.

public static void main(final String[] args) throws Exception { 
    try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) { 
     final ModelNode op = Operations.createOperation("shutdown"); 
     op.get("restart").set(true); 
     client.execute(op); 
    } 
} 
+1

謝謝,它也適用於我。爲了更精確,我認爲JBoss AS 7.2.0.Final相當於EAP 6.1.0.Alpha1。 – callafa 2014-08-29 08:17:09