Batch of goodness

Java EE 7: An Overview of Batch Processing - Part 2


Packing the application

Now that we have our JSL, ItemReaderItemProcessorItemWriter, and our servlet ready, it is time to package them and get ready to deploy.

You can deploy your batch application as any of the supported Java EE archives (for example, .war.jar, or .ear). You can bundle your batch artifact classes along with other Java EE classes (such EJB beans and servlets).

The only special requirement is that you need to place your job JSLs under the META-INF/batch-jobs directory for .jar files. For.war archive types, place your job JSLs under the WEB-INF/classes/META-INF/batch-jobs directory.

Deploying and running the Payroll sample application in Glassfish 4.0

Let's deploy the payroll application that we have developed into the GlassFish 4.0 application server. GlassFish 4.0 is the reference implementation (RI) for the Java EE 7.0 specification and contains the RI for JSR 352 as well. You can find more information about GlassFish 4.0 at and about the Java Batch 1.0 RI at

Installing and starting GlassFish 4.0

You can download GlassFish 4.0 from and then install it. Start GlassFish 4.0 by opening a command window and running the following command:

<GlassFish Install Dir>/bin/asadmin start-domain


Because the sample payroll application uses a database (to write out processed data), we need a database running before we can run our application. You can start the Apache Derby database by running the following command:

<GlassFish Install Dir>/bin/asadmin start-database

Compiling, packaging and deploying the Payroll application

First, create a new directory named hello-batch. Then change to the hello-batch directory:

cd hello-batch


To compile and package, run the following command, which creates hello-batch.war under the target directory:

mvn clean package


To deploy hello-batch.war, run the following command:

<GlassFish Install Dir>/bin/asadmin deploy target/hello-batch.war


If you want to redeploy the application, you can run the following command:

<GlassFish Install Dir>/bin/asadmin deploy -force target/hello-batch.war

Running the Payroll Application

Once you deploy the hello-batch.war file, you can run the application by accessing http://localhost:8080/hello-batch/PayrollJobSubmitterServlet from a browser. Accessing this URL should present the screen shown in Figure 2.

Figure 2

Click the Calculate Payroll button and you should see a new entry in the table, as shown in Figure 3.

Figure 3

Click the Refresh button and you should see the Exit Status and End Time columns updated for the latest job (see Figure 4). The Exit Status column shows whether the job failed or completed successfully. Since our SimplePayrollJob doesn't have any errors (at least not yet!), the Exit Status displays COMPLETED.

Figure 4

Click the Calculate Payroll and Refresh buttons a few more times. Note that each time a job is started, a new execution ID (and instance ID) is given to the job, as shown in Figure 5.

Figure 5



Mahesh Kannan
Mahesh Kannan

What do you think?

JAX Magazine - 2014 - 03 Exclucively for iPad users JAX Magazine on Android


Latest opinions