(2) [Avatar] Offline
Hi - I bought this book last week and still struggling to get the sample code running. I can compile it fine and while running it is giving this error :

77-56$ java -jar ch01-1.0.0.jar
Failed to load Main-Class manifest attribute from

Please let me know, am I doing something wrong.

arnaud.cogoluegnes (73) [Avatar] Offline
Re: how to run sample code

Chapter 1 covers how to launch the job from a JUnit test (thus from Eclipse or Maven). You can learn more about launching jobs in chapter 4 (the command line is covered).

The ch01-1.0.0.jar file you packaged contains only the definition of the job (classes + XML configuration), not the class to launch the job. There's such a launching class in Spring Batch itself, CommandLineJobRunner (chapter 4 covers all of this).

If you're using Maven, here's a trick to launch the batch from the command line, with the Maven exec plugin. Launch the following command (update your code from , I've just added the necessary configuration file!):

mvn exec:java -Dexec.mainClass="" -Dexec.args="job-context.xml importProducts inputResource=classpath:/input/ targetDirectory=./target/importproductsbatch/ targetFile=products.txt" -Dexec.classpathScope="test"

you won't see much, as the database lives only for the test execution, but you should see the uncompressed file in the target/importproductsbatch directory.

hope that helps and thanks for your interest in the book.