public static Map<String, Command> loadCommands(String pkgName, Class[] classArgs,
      Object[] objectArgs) {
    Map<String, Command> commandsMap = new HashMap<>();
    Reflections reflections = new Reflections(Command.class.getPackage().getName());
    for (Class<? extends Command> cls : reflections.getSubTypesOf(Command.class)) {
      // Add commands from <pkgName>.command.*
      if (cls.getPackage().getName().equals(pkgName + ".command")
          && !Modifier.isAbstract(cls.getModifiers())) {
        // Only instantiate a concrete class
        Command cmd = CommonUtils.createNewClassInstance(cls, classArgs, objectArgs);
        commandsMap.put(cmd.getCommandName(), cmd);
      }
    }
    return commandsMap;
  }
public static Map < String , Command > loadCommands ( String pkgName , Class [ ] classArgs , Object [ ] objectArgs ) { Map < String , Command > commandsMap = new HashMap < > ( ) ; Reflections reflections = new Reflections ( Command . class . getPackage ( ) . getName ( ) ) ; for ( Class < ? extends Command > cls : reflections . getSubTypesOf ( Command . class ) ) { if ( cls . getPackage ( ) . getName ( ) . equals ( pkgName + ".command" ) && ! Modifier . isAbstract ( cls . getModifiers ( ) ) ) { Command cmd = CommonUtils . createNewClassInstance ( cls , classArgs , objectArgs ) ; commandsMap . put ( cmd . getCommandName ( ) , cmd ) ; } } return commandsMap ; }
Get instances of all subclasses of {@link Command} in a sub-package called "command" the given
package.

@param pkgName package prefix to look in
@param classArgs type of args to instantiate the class
@param objectArgs args to instantiate the class
@return a mapping from command name to command instance