Submitting a Java batch job

You can submit a job for your Java™ batch application and run that Java batch application on a WebSphere® Application Server traditional or Liberty server.

Before you begin

Note: Java batch is only supported in WebSphere Application Server traditional V9 and in WebSphere Application Server Liberty V8.5 and V9.
Complete the following steps:
  1. Click Help > Install WebSphere Software to install the Java batch feature for WebSphere Application Server Developer Tools for Eclipse.
  2. Create a Java batch project.
  3. Create a Java batch job in the Java batch project.
  4. Ensure that your Java batch application is packaged.

    If you are targeting a Liberty server, the wizard automatically packages the batch project in a web archive (WAR) file. You can also package your project in other resources. To target a WebSphere Application Server traditional server, package your project in an enterprise archive (EAR) file.

  5. You can create a server. Create a Liberty server, create a remote Liberty server, or create a WebSphere Application Server traditional server. If you are targeting a Liberty server, configure it for Java batch applications.
  6. Deploy the resource that contains the batch application to a server.
    1. Select Window > Show View > Servers.
    2. Right-click the server and select Add and Remove....

      The Add and Remove wizard displays.

    3. Select the resource that you want to deploy from the Available area to the Configured area by clicking Add >; then, click Finish.
  7. Start the server.
    1. Select Window > Show View > Servers.
    2. Right-click the server and select Start.

Procedure

  • To submit a job for your Java batch application and run that Java batch application on a Liberty server, complete the following steps:
    1. For Java batch projects, in the Enterprise Explorer view, select a Java batch project, and then select src > META-INF > batch-jobs > batch_job.xml.
    2. Right-click the batch_job.xml file.
    3. Select Run As > Java EE Batch Job.
    4. Select the target server on which the Java batch job runs.
    5. Specify the user ID and password of a user who is configured in your Liberty server.

      This user ID is used to submit Java batch jobs.

    6. In the Job parameters section, enter any job parameters that you defined for your batch application.
      1. Click Add.
      2. The Add Parameter dialog is displayed.
      3. Enter or select the name of the parameter.
      4. Enter the value of the parameter, and then click OK.
      5. Repeat the process to add any additional parameters.
    7. Click Apply and then Run.
  • To submit a job for your Java batch application and run that Java batch application on a WebSphere Application Server traditional server, complete the following steps:
    1. To create a servlet, right-click the web project and select New > Servlet.

      The tools display the Create Servlet wizard.

    2. Enter values for the Java package and Class name fields.
    3. Click Finish.
    4. Enter the following input on the doGet implementation for the servlet:
      JobOperator jobOperator = BatchRuntime.getJobOperator();
      jobOperator.start("job", PROP);

      The PROP value can be null, or it can be an instance of java.util.Properties that contains job parameters.

    5. To run the servlet on a server, select Run As > Run on Server.

      The tools display the Run on Server wizard.

    6. If the server that you created is not selected, select it, and click Next.
    7. If the EAR file that you created is not selected, select it, and click Finish.

Results

You submitted a batch job to your server so that you can run your Java batch application.

[Liberty] If the job submission is successful, a dialog shows information about the job instance that you submitted, and job execution details. If the submission fails, a dialog shows possible causes of the problem.

Note: If application security is enabled on the server, and batch authorization is not configured, the job fails with the following message:
CWWKY0304W: User <user name> is not authorized to start batch jobs.
Application security is enabled either directly through one of the appSecurity features or indirectly through a feature that enables it automatically, such as jaxrs. For more information about configuring batch authorization, see Securing the Liberty batch environment.

If the information provided in the dialog is not sufficient to diagnose the problem, or if you are not targeting a Liberty server, you can check the Error log view to see more details about the failure. You can also check the server logs, which are located in the wlp\usr\servers\<server>\logs directory.