August 17, 2023

tJava – Docs for ESB 5.x

tJava

tJava_icon32.png

tJava properties

Component family

Custom Code

 

Function

tJava enables you to enter
personalized code in order to integrate it in Talend program. You can execute this code
only once.

Purpose

tJava makes it possible to extend
the functionalities of a Talend Job through using Java
commands.

Basic settings

Code

Type in the Java code you want to execute according to the task
you need to perform. For further information about Java functions
syntax specific to Talend, see
Talend Studio Help Contents (Help > Developer
Guide > API Reference).

For a complete Java reference, check http://docs.oracle.com/javaee/6/api/

Note

This component offers the advantage of the dynamic
schema feature. This allows you to retrieve unknown columns
from source files or to copy batches of columns from a
source with­out mapping each column individually. For
further information about dynamic schemas, see
Talend Studio User
Guide
.

Advanced settings

Import

Enter the Java code that helps to import, if necessary, external
libraries used in the Main code box
of the Basic settings view.

 

tStatCatcher Statistics

Select this check box to gather the Job processing metadata at a
Job level as well as at each component level.

Global Variables

ERROR_MESSAGE: the error message generated by the
component when an error occurs. This is an After variable and it returns a string. This
variable functions only if the Die on error check box is
cleared, if the component has this check box.

A Flow variable functions during the execution of a component while an After variable
functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl +
Space
to access the variable list and choose the variable to use from it.

For further information about variables, see Talend Studio
User Guide.

Usage

This component is generally used as a one-component subjob.

Limitation

You should know Java language.

Scenario: Printing out a variable content

The following scenario is a simple demo of the extended application of the tJava component. The Job aims at printing out the number of
lines being processed using a Java command and the global variable provided in Talend Studio.

Use_Case_tJava1.png

Setting up the Job

  1. Select and drop the following components from the Palette onto the design workspace: tFileInputDelimited, tFileOutputExcel, tJava.

  2. Connect the tFileInputDelimited to the
    tFileOutputExcel using a Row Main connection. The content from a delimited
    txt file will be passed on through the connection to an xls-type of file
    without further transformation.

  3. Then connect the tFileInputDelimited
    component to the tJava component using a
    Trigger > On
    Subjob Ok
    link. This link sets a sequence ordering tJava to be executed at the end of the main
    process.

Configuring the input component

  1. Set the Basic settings of the tFileInputDelimited component.

    Use_Case_tJava2.png
  2. Define the path to the input file in the File
    name
    field.

    The input file used in this example is a simple text file made of two
    columns: Names and their respective
    Emails.

  3. Click the Edit Schema button, and set the
    two-column schema. Then click OK to close
    the dialog box.

    Use_Case_tJava3.png
  4. When prompted, click OK to accept the
    propagation, so that the tFileOutputExcel
    component gets automatically set with the input schema.

Configuring the output component

Set the output file to receive the input content without changes. If the file does
not exist already, it will get created.

Use_Case_tJava4.png

In this example, the Sheet name is
Email and the Include
Header
box is selected.

Configuring the tJava component

  1. Then select the tJava component to set
    the Java command to execute.

    Use_Case_tJava5.png
  2. In the Code area, type in the following
    command:

    In this use case, we use the NB_Line variable. To
    access the global variable list, press Ctrl + Space bar on your keyboard and
    select the relevant global parameter.

Job execution

Save your Job and press F6 to execute it.

Use_Case_tJava6.png

The content gets passed on to the Excel file defined and the Number of lines
processed are displayed on the Run console.


Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x