关闭

java程序中给Kettle传参数

1287人阅读 评论(0) 收藏 举报
分类:

import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.LogWriter;
import org.pentaho.di.core.util.EnvUtil;
import org.pentaho.di.job.Job;
import org.pentaho.di.job.JobEntryLoader;
import org.pentaho.di.job.JobMeta;
import org.pentaho.di.trans.StepLoader;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;


public class EtlParams {


public static void main(String[] args) {
// TODO Auto-generated method stub
runJob("D:\\etl\\params1.kjb");
}
public static void runJob(String filename) {
try {
StepLoader.init();
EnvUtil.environmentInit();
JobEntryLoader.init();
JobMeta jobMeta = new JobMeta(LogWriter.getInstance(),filename,null);
Job job = new Job(LogWriter.getInstance(),StepLoader.getInstance() ,null,jobMeta);
job.getJobMeta().setInternalKettleVariables(job);
job.setVariable("XMLPATH", "D:\\etl\\gz_zb_zb");
job.setVariable("ZB_FJD", "23d267b7aad54f5b961f66fac791b356");
job.execute(); // You can pass arguments instead of null.
job.waitUntilFinished();
if ( job.getErrors() > 0 )
{
throw new RuntimeException( "There were errors during transformation execution." );
}
}
catch ( KettleException e ) {
System.out.println(e);
}
}

}

job里,在需要调用的地方直接${变量名},调用就可以了

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:238128次
    • 积分:2972
    • 等级:
    • 排名:第11828名
    • 原创:8篇
    • 转载:319篇
    • 译文:0篇
    • 评论:11条
    文章分类
    最新评论