It's often convenient to run jcmd command programmatically from within a testcase to get some information or to adjust options.

See the template below:

// import;
// import;

 public static void reloadCompilerDirectives(String filename) {
    String result;
    result = doRunDcmd("compilerDirectivesClear", new String[]{""});
    result = doRunDcmd("compilerDirectivesAdd", new String[]{ filename });

  private static String doRunDcmd(String operationName, String operationArgs[]) {
      ObjectName objectName = 
          new ObjectName("");
      MBeanServer mbeanServer = 
      Object[] params = new Object[] { operationArgs };
      String[] signature = new String[]{ String[].class.getName() };
      return(String) mbeanServer.invoke(objectName, operationName, params, signature);