Reputation: 395
I'm able to restart JBoss AS 7.2.0 Final using Jboss CLI with the following command:
jboss-cli.bat --connect --controller=IP:9999 --command=:shutdown(restart=true)
Now i need to do it programmatically from a java class, i've tried using the Jboss cli API, here after my code, but it only performs a shutdonw and doesn't restart!
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());
}
Any idea please?
Upvotes: 3
Views: 1929
Reputation: 17760
There really is no JBoss AS 7.2.0.Final but I tested the following on WildFly 8 and JBoss EAP 6.x and it worked for me. Note that port 9990
is used in WildFly and port 9999
is used for 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);
}
}
Upvotes: 4