Interface KeywordExecutable


  • public interface KeywordExecutable
    An interface used with the Java ServiceLoader to auto-discover classes executable with a convenient keyword on the command-line.

    All implementing classes who have an entry in META-INF/services/KeywordExecutable on the classpath will be constructed by the ServiceLoader, so they should be lightweight and quickly constructible with a mandatory no-argument constructor. Because of this, implementing classes could simply be factories which execute a different class, if that class is expensive to construct or cannot have a no-argument constructor.

    One way to easily create META-INF/services files is to use the AutoService annotation.

    If the implementing class also wishes to have a redundant main method, it may be useful to simply implement main as:
    new MyImplementingClass().execute(args);

    • Method Detail

      • keyword

        String keyword()
        Returns:
        Keyword which identifies this service
      • usage

        default String usage()
        Returns:
        Usage for service
      • description

        String description()
        Returns:
        Description of service
      • execute

        void execute​(String[] args)
              throws Exception
        Execute the item with the given arguments.
        Parameters:
        args - command-line arguments to pass to the executed class
        Throws:
        Exception