
Component family |
Custom Code |
|
Function |
tJava enables you to enter |
|
Purpose |
tJava makes it possible to extend |
|
Basic settings |
Code |
Type in the Java code you want to execute according to the task For a complete Java reference, check http://docs.oracle.com/javaee/6/api/ NoteThis component offers the advantage of the dynamic |
Advanced settings |
Import |
Enter the Java code that helps to import, if necessary, external |
|
tStatCatcher Statistics |
Select this check box to gather the Job processing metadata at a |
Global Variables |
ERROR_MESSAGE: the error message generated by the A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see Talend Studio |
|
Usage |
This component is generally used as a one-component subjob. |
|
Limitation |
You should know Java language. |
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.

-
Select and drop the following components from the Palette onto the design workspace: tFileInputDelimited, tFileOutputExcel, tJava.
-
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. -
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.
-
Set the Basic settings of the tFileInputDelimited component.
-
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. -
Click the Edit Schema button, and set the
two-column schema. Then click OK to close
the dialog box. -
When prompted, click OK to accept the
propagation, so that the tFileOutputExcel
component gets automatically set with the input schema.
Set the output file to receive the input content without changes. If the file does
not exist already, it will get created.

In this example, the Sheet name is
Email and the Include
Header box is selected.
-
Then select the tJava component to set
the Java command to execute. -
In the Code area, type in the following
command:123String var = "Nb of line processed: ";<span></span>var = var + globalMap.get("tFileInputDelimited_1_NB_LINE");<span></span>System.out.println(var);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.