Customize SBAL

SBAL can be customized, especially:

  • The configuration properties loading
  • The way to configure Log4j

These 2 goals are reached by extending the BatchLauncher class.

Customizing Log4j configuration

You need to create a class that implements the LogConfigurator interface. The method

public void configure(File confDir, String jobName)

allows you to configure log4j.

confDir
is the ${batch.home}/conf directory
jobName
The current job name passed through the '-b' option.

Sample: see net.sf.spring.batch.impl.Log4jConfigurator.

Customizing properties loader

You need to create a class that implements the PropertiesLoader interface.

The following methods:

public abstract Properties loadProperties(File confDir, String batchName) 
public abstract Properties loadProperties(File confDir, String batchName, String globalPropertyFile)

allows you to load properties files.

confDir
is the ${batch.home}/conf directory
batchName
The current job name passed through the '-b' option.
globalPropertyFile
The property file passed throught the '-g' option.

Sample: see net.sf.spring.batch.impl.DefaultPropertiesLoader.

Putting it together

Once you have customized your properties loader, and log4j configuration you need to create a class that extends BatchLauncher class and re-implement the main method.

public class MyBatchLauncher extends BatchLauncher {

        public static void main(String[] args) {
                MyBatchLauncher batchLauncher = new MyBatchLauncher();
                batchLauncher.setLog4jConfigurator(new Log4jConfigurator());
                batchLauncher.setPropertiesLoader(new DefaultPropertiesLoader());
                int result = batchLauncher.init(args);
                if (result == STOP)
                        batchLauncher.exit(0);
                if (result == ERROR)
                        batchLauncher.exit(-9999);
                result = batchLauncher.run();
                batchLauncher.exit(result);
        }
}