Programatically start/stop JBoss
roque69 Jun 17, 2005 7:34 AMHello.
I'm trying to programatically start and stop JBoss server, but I'm having some problems. Actualy, my code to start/stop is as follows:
import org.jboss.*;
...
private void startJBoss() {
try {
String str[]={};
Class c = Class.forName("org.jboss.Main");
Main ob = (Main)c.newInstance();
ob.main(str);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
private void stopJBoss() {
try {
String str[]={"-S"};
Class c = Class.forName("org.jboss.Shutdown");
Shutdown ob = (Shutdown)c.newInstance();
ob.main(str);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
In the classpath I have added the run.jar and shutdown.jar from the bin directory of JBoss. Now the problem comes when I start JBoss where I receive the following exceptions:
[Server] Starting General Purpose Architecture (GPA)...Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/Element at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) at java.lang.Class.getConstructor0(Unknown Source) at java.lang.Class.newInstance0(Unknown Source) at java.lang.Class.newInstance(Unknown Source) at org.jboss.mx.modelmbean.RequiredModelMBeanInstantiator.instantiate(RequiredModelMBeanInstantiator.java:37) at org.jboss.mx.server.MBeanServerImpl.<init>(MBeanServerImpl.java:205) at org.jboss.mx.server.MBeanServerBuilderImpl.newMBeanServer(MBeanServerBuilderImpl.java:56) at javax.management.MBeanServerFactory.newMBeanServer(Unknown Source) at javax.management.MBeanServerFactory.createMBeanServer(Unknown Source) at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:349) at org.jboss.system.server.ServerImpl.start(ServerImpl.java:310) at org.jboss.Main.boot(Main.java:195) at org.jboss.Main$1.run(Main.java:463) at java.lang.Thread.run(Unknown Source)
If I remove the shutdown.jar from the classpath, I can start JBoss without problems, but then, I don't have any option to stop it.
Any other way to start/stop JBoss programatically.
Thanks,
Miguel