Class Application

All Implemented Interfaces:
ApplicationMetadata, Component, Receiver<Transmittable>, Transmitter<Transmittable>, Named, NamedObject, PackagePathed, Versioned, Broadcaster, Listener, Repeater, Transceiver
Direct Known Subclasses:

public abstract class Application extends BaseComponent implements Named, ApplicationMetadata
Base class for KivaKit applications. Handles command line parsing, project initialization and configuration.


Because this class extends BaseRepeater and has a Logger that listens to the application class, all Applications automatically inherit logging functionality via the convenience methods in Repeater.


The Application object should be constructed in the main(String[]) Java entrypoint and the run(String[]) method should be called. This can be done in one step:

 public static class MyApplication extends Application
     public static void main( String[] arguments)
         new MyApplication().run(arguments);


Command Line Parsing

For within the application implementation in the onRun() method, the Application class provides convenient access to the parsed command line:

Important Note: Project Initialization

All applications must pass one or more Projects to the Application constructor to ensure that all of the application's dependent project(s) are correctly initialized. See Project for details.


The run(String[]) method will perform the following steps:

  1. Call onProjectInitializing()
  2. Initialize and install the Project passed to the constructor
  3. Call onProjectInitialized()
  4. Parse command line arguments using:
  5. Call the application implementation in onRun()
jonathanl (shibo)
See Also:
BaseRepeater, CommandLine, SwitchParser, ArgumentParser
  • Method Details

    • get

      public static Application get()
      The currently running application
    • argument

      public <T> T argument(int index, ArgumentParser<T> parser)
      The non-switch argument at the given index parsed using the given argument parser
    • argument

      public <T> T argument(ArgumentParser<T> parser)
      The first non-switch argument parsed using the given argument parser
    • arguments

      public ArgumentList arguments()
      All non-switch command line arguments
    • commandLine

      public CommandLine commandLine()
      The parsed command line
    • commandLineDescription

      public String commandLineDescription(String title)
      This command line in a text box intended for user feedback when starting an application
    • description

      public String description()
      Specified by:
      description in interface ApplicationMetadata
      A description of the application for use in help
    • exit

      public void exit(String message, Object... arguments)
      Exits the application with the given message formatted by Message.format(String, Object...)
      message - The message
      arguments - Arguments to interpolate into the message
    • get

      public <T> T get(SwitchParser<T> parser)
      The value for the command line switch parsed by the given switch parser, if any
    • get

      public <T> T get(SwitchParser<T> parser, T defaultValue)
      The value for the command line switch parsed by given switch parser or the default value if the switch does not exist
    • has

      public <T> boolean has(SwitchParser<T> parser)
      True if this application has a value for the command line switch parsed by the given parser
    • identifier

      public Application.Identifier identifier()
    • localizedProperties

      public PropertyMap localizedProperties(Locale locale)
    • project

      public Project project()
    • properties

      public PropertyMap properties()
    • run

      public final void run(String[] arguments)
      Runs the application by calling onRun() given the arguments from the Java main(String[]) application entrypoint. Operations occur in this order:
      1. onRunning() is called to indicate that running is about to start
      2. Command line arguments are validated and parsed into a CommandLine
      3. onConfigureListeners() is called to allow redirection of output
      4. onProjectInitializing() is called before the Project for this application is initialized
      5. Project.initialize() is called
      6. onProjectInitialized() is called
      7. onRun() is called
      8. onRan() is called
      9. The application exits
      arguments - Command line arguments to parse
    • showCommandLine

      public void showCommandLine()
    • version

      public Version version()
      Specified by:
      version in interface Versioned
      The application version as specified in the resource "/"