SourceForge.net Logo > AJCT Project > Home > Usage
   Configuration Sources
   Configuration Targets
   Startup Parameters
   Initialization
   Substitution (& escaping)
   Extending AJCT
   Download




AJCT – Another Java Configuration Tool

Startup parameters

By default, AJCT looks for the file <hostname>.config.xml in the classpath. If required, any source can be used as initial configuration source. All that is required is to specify it at the command line.

Note: the default namespace is 'config'.

Parameter

Description

<namespace>.type

Type of the initial config source. Possible values: xml, system, LDAP1, driverconfig

The other parameters are as described for the given configuration source, prepended with the namespace.

Example 1: use the xml file 'development.config.xml' located in the class path of the JVM.

java -Dconfig.type=xml -Dconfig.filename=development.config.xml -Dconfig.location=classpath MyApp

Example 2: use the system properties starting with 'myapp'. Load them into the section 'system'.

java -Dconfig.type=system -Dconfig.section=system -Dconfig.namespace=myapp MyApp

Example 3: use the xml file 'C:\config\test.config.xml'.

java -Dconfig.type=xml -Dconfig.filename=C:\config\test.config.xml -Dconfig.location=file MyApp

Initialization

AJCT supports both explicit and lazy initialization.

Lazy

If you use AJCT (any call to ConfigManager except init) before explicit initialization, AJCT is initialized lazy.

Explicit

Explicit initialization uses a call to init() prior to any other call.

ConfigManager.init(AjctConfiguration.getDefaultAjctConfig("myapp"));

init() needs an AjctConfiguration configuration object. This can be the default (AjctConfiguration.getDefaultAjctConfig()) or one that you configured by coding:

//Create a configuration source in the namespace myapp
AjctConfiguration configuration = AjctConfiguration.getDefaultAjctConfig("myapp");
//Setup automatic reload every minute
configuration.setReloadInterval(60000);
//Make the section/key case sensitive
configuration.setSearchIgnoreCase( false );
//Initialize AJCT
ConfigManager.init(configuration);

Difference between lazy and explicit

Beyond the obvious difference of being able to configure AJCT, the biggest difference is that you are unable to trap errors when AJCT fails to initialize when using lazy initialization.

Substitution (and how to escape them)

Reusing parts of your configuration is one of the powers of AJCT. In order to achieve this, AJCT supports substitution in the values. The syntax for substitution is [sectionName]{keyName}
See also the
XML configuration source example.

The last step after reading in the configuration is processing all substitutions (except for parameters for 'include' or 'export' statements).

Pitfalls:

  • Circular references are not supported. They will not cause AJCT to loop; neither will they throw an exception. The results are however unpredictable.
  • Parameters to included configuration sources or export configurations are replaced with the values known at that point. Eg: if you have a parameter filename with the value [locations]{resourceRoot}/aFile.xml, and you define the value for [locations]{resourceRoot} only after it is used, it will not work.
  • Escaping is done using the '\' (backslash). The value \[locations]{resourceRoot}/aFile.xml will not cause substitution to take place. The backslash itself needs to be escaped by doubling it.



This file was last modified