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:
String var = "Nb of line processed: "; var = var + globalMap.get("tFileInputDelimited_1_NB_LINE"); 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.