Using version provider

Default version provider

By default SBAL uses the DefaultVersionProvider class to find the current batch version. This class expects its version attribute to be set from the spring configuration file:

        <bean id="version"
                class="net.sf.spring.batch.impl.DefaultVersionProvider">
                <property name="version">
                        <value>1.0.0</value>
                </property>
        </bean>

But you can provide your own version provider by implementing the net.sf.spring.batch.VersionProvider interface, and declare your class as the bean with the version id.

Custom version provider

If you want to have the '-v' option to display the implementation version from the manifest of a jar, you can do:

import net.sf.spring.batch.VersionProvider;

public class ClassBasedVersionProvider implements VersionProvider {

        protected String className;
        
        public String findVersion() {
                if(className==null)
                        return "unknown";
                try {
                        return Class.forName(className).getPackage().getImplementationVersion();
                } catch (ClassNotFoundException e) {
                        return "unknown";                       
                }
        }

        /**
         * @param className the className to set
         */
        public void setClassName(String className) {
                this.className = className;
        }

}

and declare in context file:

        <bean id="version"
                class="net.sf.spring.batch.impl.ClassBasedVersionProvider">
                <property name="className">
                        <value>com.mycompany.mybatch</value>
                </property>
        </bean>