Adding a batchlet step to a Java batch job

You can add a batchlet step to the xml file of a Java™ batch job. Use a batchlet step to perform task-oriented processing such as running a command or transferring a file.

Before you begin

A batchlet step is started once, runs to completion, and returns an exit status. Unlike a chunk step, the batchlet step does not read, process, and write individual items, which are data records.

Complete the following tasks:
  • Install the Java batch feature for WebSphere® Application Server Developer Tools for Eclipse. This feature is optional. You can install it from Help > Install WebSphere Software.
  • Create a Java batch project.
  • Create a Java batch job in the Java batch project.

About this task

Use the Job Specification Language (JSL) editor to create the batchlet step. Then, create a batchlet class and add it to the batchlet step to implement the step.

Procedure

  1. In the Job Specification Language (JSL) editor, open the xml file for your Java batch job.

    The JSL editor opens automatically if you click Finish when you create a Java batch job. An xml file with the same name as the batch job displays in the JSL editor.

    If you are adding a step to an existing Java batch job xml file, complete the following steps to open the xml file in the JSL editor:
    1. In the Enterprise Explorer view, select your Java batch project that you created.
    2. Select src > META-INF > batch-jobs.
    3. Double-click the xml file for your Java batch job.

      The file displays in the JSL editor.

  2. Select the job node on the Overview tab; click Add.
  3. Select Step; click OK.
  4. Optional: Change the ID in the ID* field of the Details tab.
  5. Select the step node on the Overview tab; click Add.
  6. Select Batchlet; click OK.
  7. Include a batchlet class to implement the batchlet step.

    You can create a new batchlet class for your project, use an existing batchlet class within your project, or use an existing batchlet class in another project that is in the class path of your project. Complete one of the following tasks:

    1. Create a class to implement this batchlet step.
      1. Click the reference link on the Details tab.

        The New Batchlet Class wizard displays.

      2. In the Java package field, specify the name of the package.
      3. In the Class name field, specify the name of the class.
      4. Optional: Optional: In the Super class field, specify the name of the super class.
      5. Optional: Optional: In the Interfaces field, add more interfaces to be implemented by this class.
      6. For Batch artifact loading options, accept the default value of Use the fully qualified name of the class.
        • If you select the Use the fully qualified name of the class option, the runtime environment treats the batch artifact reference as a class name and loads the reference through the thread context class loader. The loading is done to resolve a batch artifact reference when the archive loader returns null for this reference.
        • If you select the Use context and dependency injection (CDI) option, the runtime environment uses the CDI implementation-specific loader to resolve the batch artifact reference by using the bean name that you specify.
        • If you select the Add the class to the batch.xml file option, the runtime environment uses the archive loader to resolve the reference by looking for the specified identifier in the batch.xml file.
    2. Use an existing batchlet class to implement the batchlet step.
      1. Click Browse on the Details tab.
      2. Search for classes by name by selecting Search for classes and then typing the class name.
      3. Select the class name from Matching items.
      4. As an alternative to the search, if a batch.xml file exists, select Browse entries in batch.xml and then select one of the entries from the table.
      5. Click OK.
  8. Click Finish.

Results

You created a batchlet step for a Java batch job. You included a batchlet class in the batchlet step so that you can implement the step in the Java batch job. You created the batchlet class or used an existing one.

Feedback