====== Spring Batch ====== ===== Execute with Test Resources ===== To execute a Spring Batch programm with test resource using Maven the ''exec.classpathScope'' needs to be set on the ''mvn'' command. mvn exec:java -Dexec.classpathScope="test" ===== Output ===== ==== No Output ==== Sometimes there is nothing to be written as there is no output. A NoopItemWriter can be created like this: public class NoopItemWriter implements ItemWriter { @Override public void write(List items) throws Exception { // nothing to do here } } The item writer is added to the launch context file. ===== Input ===== ==== Declare Comment Lines ==== Depending on the system and file comments may start with very different characters. These can be specified in the item writer (if it is supported by the implementation) like this: # ; ! ==== Skipping Empty Lines ==== The default reader implementation does not skip empty lines. There is a reader implementation from Robert Kasanicky where empty lines are treated as comments. The implementation can be found {{::extflatfileitemreader.java|here}}. ==== Skipping First Lines ==== CSV files often start with the column names. Generally these must be skipped when processing the file. If you are using the [[http://docs.spring.io/spring-batch/apidocs/org/springframework/batch/item/file/FlatFileItemReader.html | FlatFileItemReader]] you can just add a property to your itemReader bean like this: ==== CSV File Input ==== Reading a delimited file with Spring Batch is a combination of using a file item reader, line mapper and line tokenizer. ==== Tab Delimited Values ==== To declare the tab character as a delimiter "\t" cannot be specified. Instead use the Java constant from the Spring framework. Don't forget to add the namespance to the head of the xml file. ===== Create Jar with Dependencies ===== To embed all dependencies and create an executable jar the pom.xml must be extended by the maven-assenbly-plugin. maven-assembly-plugin org.springframework.batch.core.launch.support.CommandLineJobRunner jar-with-dependencies Create the jar with executing the following line on the command line mvn clean compile assembly:single Execute the program with java -jar program-jar-with-dependencies.jar launch-context.xml jobid {{tag>devel java}}