Java call Kettle Passing argument instances to job (Task) and transformation (transform)

Source: Internet
Author: User
Tags throw exception

Recently, the data of one system is synchronized to another system, and the data result of the new system is required to be synchronized to another system data table in real time.
That is, dynamically passing an associated ID. Because the old system is made of VB, can not provide WebService interface, and the synchronization of the table involves more than 10 tables, and the two system table structure is completely different, so think of kettle.
Java Integrated Kettle Online has a ready-made instance, very simple. such as: http://bakcom.iteye.com/blog/1399587

Although the online article has said that Java can pass parameters to kettle, but only found the transfer parameters to the conversion of the article, no argument passed to Job,kettle in how to use Java passed parameters. Share the above questions today.

/** * This test class with caution!!!!!!! * * @param args */public static void main (string[] args) {String datetime = "2014-12-19 23:20:45"; String[] params = {"707", DateTime}; Pass parameter String Path = "F:\\JOB7.KJB";//runtransfer (params, path); Runjob (params, path);//Runjob ();//jbresource ();} /** * Run Convert file method * @param params multiple parameter variable value * @param path of ktrpath conversion file, suffix ktr */public static void Runtransfer (string[] params, S Tring Ktrpath) {trans trans = Null;try {////Initialize//Convert Meta Object Kettleenvironment.init ();//Initialize Envutil.environmentinit (); Transmeta Transmeta = new Transmeta (ktrpath);//convert trans = new trans (transmeta);//Perform conversion trans.execute (params);// Wait for the conversion execution to end trans.waituntilfinished ();//Throw exception if (trans.geterrors () > 0) {throw new Exception ("There is errors during" Tran Sformation exception! (Exception occurred during transmission) ");}} catch (Exception e) {e.printstacktrace ();}} /** * Java calls Kettle's job * * @param jobname * such as: String fname= "D:\\KETTLE\\INFORMIX_TO_AM_4.KTR"; */public static void Runjob (string[] params, String Jobpath) {try {KeTtleenvironment.init ();//JobName is the path and name of the job script Jobmeta Jobmeta = new Jobmeta (Jobpath, NULL); Job Job = new Job (null, Jobmeta);//pass parameters to the job script, get parameter values in script: ${parameter name}//job.setvariable (Paraname, Paravalue); Job.setvariable ( "id", params[0]); Job.setvariable ("DT", params[1]); Job.start (); job.waituntilfinished (); if (job.geterrors () > 0) { throw new Exception ("There is errors during job exception! ( Execute job exception) ");}} catch (Exception e) {e.printstacktrace ();}}


<span style= "font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); " > above is the fragment. The method of invoking tasks and transforms is implemented, and I only give the method to invoke the task and transform the file, and the connection database is skipped here. </span>

Here's how to use the parameters passed by Java.

Conversions online with examples, converting tables, opening inputs, finding "get system Info"


For variable definition, select command parameter 1 ... N Can



You can refer to the parameters in my example.

However, our migration work is performed sequentially, the call conversion is not enough, the job needs to define the order of execution,

For example, the above conversion as the first step, the operation of the other steps, then on this basis, you can draw a job




At this point, we have to live with Java data, and this job needs to pass parameters to the Test2 transformation.

In fact, it is very simple, open test2, switch to parameter selection, the Java definition of the parameters written in, remember with {}



So the merit is made. Java has been able to successfully pass values to Job,job to pass the value to the transformation.

Clicking the run this job defines the parameter names in variable consistent with the parameters passed by Java, and can be tested with write values.


Note: Tasks and conversions are stored in a file format, and the conversion referenced in a task is also a file format,

Otherwise, database support is required, and the database method is called.

Java call Kettle Passing argument instances to job (Task) and transformation (transform)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.