Performing one-off pieces of logic using tJava
The tJava
component allows one-off logic to be added to a job. Common uses of tJava
include setting global or context variables prior to the main data processing stages and printing logging messages.
Getting ready
Open the job jo_cook_ch05_0000_tJava
.
How to do it…
Open the
tJava
component.Type in the following code:
System.out.println("Executing job "+jobName+" at "+TalendDate.getDate("CCYY-MM-dd HH:mm:ss"));
Run the job. You will see that message is printed showing the job name and the date and time of execution.
How it works…
If you examine the code, you will see that the Java code is simply added to the generated code as is. This is why you must remember to add ;
to the end of the line to avoid compilation errors.
See also
Setting context variables and globalMap variables using tJava, in this chapter.