Skip to main content Skip to complementary content

Pass new values to context variables

You can also pass new values to the context variables when calling a Talend Job in a Java program. This functionality is useful in real-world cases, because the values may be provided by other code snippets.

Procedure

  1. Edit the TalendExample.java class.

    In this example, add two lines to the output.

    package org.talend;
    import di_demo.calljobineclipsedemo_0_1.CallJobInEclipseDemo;
    public class TalendExample {
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		CallJobInEclipseDemo talendJob=new CallJobInEclipseDemo();
    		int nb_line=2;
    		String name="Ross";
    		String [] context=new String[] {"--context_param nb_line="+nb_line,"--context_param name="+name};
    		talendJob.runJob(context);
    	}
    }
  2. Execute the TalendExample.java class.
  3. Open the file D:file/out.txt and check that the two lines of data are appended:
    talend;2014-08-04 09:34:13
    talend;2014-08-04 10:57:37
    Ross;2014-08-04 11:12:04
    Ross;2014-08-04 11:12:04

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!