0 Replies Latest reply on Sep 26, 2013 2:11 PM by shonguiz

    Programmatically manage JBoss 6.1 (through java)

    shonguiz

      Hi i want to display some informations on JBoss 6.1 like the status and the version and i also want to start/stop/restart it,  I have seen this for start / stop  but i don't find the shutdown methd in the class Main from org.jboss.system 4.0.2

       

      package com.sudipta.jboss.conf;

      import org.jboss.Main;

      public class JbossOperation {
        
      public static Main ob;
        
      static Class jbossMain;
        
      static{
        
      try {
        jbossMain
      =Class.forName("org.jboss.Main");
        ob
      = (Main)jbossMain.newInstance();
        
      } catch (ClassNotFoundException e) {
        e
      .printStackTrace();
        
      } catch (InstantiationException e) {
        e
      .printStackTrace();
        
      } catch (IllegalAccessException e) {
        e
      .printStackTrace();
        
      }

        
      }

      /**
      * START JBOSS SERVER
      * @return true if started successfully
      */

      public static boolean startServer(){
        
      boolean status=true;

        
      String str[]={"-c","default"};  
        
      try {
        ob
      .boot(str);

        
      } catch (Exception e) {  
        e
      .printStackTrace();
        
      return false;
        
      }  
        
      return status;
      }

      /**
      * STOP JBOSS SERVER
      * @return true if started successfully
      */

      public static boolean stopServer(){
        
      boolean status=true;  
        
      try {
        ob
      .shutdown();  
        
      } catch (Throwable e) {  
        e
      .printStackTrace();
        
      }  

        
      return status;
      }

      /**
      * Main method
      * @param args
      */

      public static void main(String args[]){
        
      System.out.println("---------------------Strating the server------------------");
        startServer
      ();
        
      System.out.println("---------------------Stoping the server------------------");
        stopServer
      ();
        
      System.out.println("---------------------SERVER STOPPED------------------");
      }