Java Call Kettle Pass parameter instance to job (Task) and transformation (transform)

Source: Internet
Author: User
Tags throw exception
The most recent synchronization of a system's data to another system requires that the data results of the new system be completed and synchronized to the other system datasheet 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 synchronized table involves more than 10 tables, and the two system table structure is completely different, so think of the kettle.
Java Integrated Kettle Online has a ready-made example, 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 a pass parameter to the conversion of the article, did not speak the parameters passed to the Job,kettle in the use of 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 the transform file method * @param params multiple parameter variable values * @param ktrpath the path of the transformation file, the suffix ktr/public static void Runtransfer (Stri
		Ng[] params, String 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 transition execution to end trans.waituntilfinished (); Throw exception if (trans.geterrors () > 0) {throw new Exception ("There are errors during the transformation exceptio N!
			(Abnormal during transmission) ");
		} catch (Exception e) {e.printstacktrace (); }/** * Java invoke Kettle 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 the 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 are 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 a fragment. The method of invoking the task and transformation is implemented, I only give the method of invoking the task and transforming the file, the connection database is skipped here. </span>

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

The conversion of the web has examples, the conversion of the platform, open input, find "Get system Information"


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



You can refer to the 1,2 parameter in my example.

But our migration is done sequentially, call conversions are not sufficient, and jobs are required to define the order of execution,

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




This is the problem, we want to live Java data, and this job needs to pass parameters to the Test2 conversion to use.

Actually very simple, the point opens the test2, switches to the parameter selection, writes the Java definition parameter, remembers the belt {}



This makes the difference. Java has been able to successfully pass the value to Job,job to pass the value to the transformation.

Click the run this job to define a parameter name in variable that is consistent with Java-passed parameters and can be written to test the value.


Note: Tasks and transformations are to be stored in a file format, and the translation referenced in the task is also a file format.

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

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.