Chapter 12. Configuring Program Options
Modern Java applications are typically quite flexible. Much of this flexibility takes the form of options and parameters that can be given to a program when it first starts up. In a typical example, a program may need to be told which of several related tasks it should perform and will need to be given information relevant to that task. This in turn means that the program must be able to process this information in order to know what to do. Some options, such as the major task to perform, are internal switches. Other options require a value, such as the URL of a database. Still others may require multiple options, such as a list of files to be processed.Closely related to this issue is that a well-written program can tell its users about options. There is no substitute for good documentation, but it can be very convenient for the program itself to be able to remind the user of the names of the options.Many of the tools already encountered have their own ways of doing such configuration. Ant has build files, OJB has mapping files, Java logging has property files, log4j uses XML-based configuration, and so on. This chapter will look at two general toolsJakarta CLI and Jakarta Digesterboth of which remove a lot of the tedious work that can be involved in processing configuration data.