java 调用kettle4 的transaction和job

项目中要用到用Java代码调用Kettle脚本,于是找kettle官方资料,用他们提供的jar包,通过java代码来运行kettle脚本。发现官方提供的实例都只能用于kettle3.0版的脚本,4.0的根本不支持。反复搜索,终于在Matt的新书的附件中找到了Kettle 4.0 API的相关资料,该地址是:ftp://download:[email protected]/product_ancillary/77/04706351/DOWNLOAD/635179_downloads.zip。大家可以去下载。



调用JOB的示例:
“public void runJob(String jobname){
  try {
   KettleEnvironment.init();
   //jobname 是Job脚本的路径及名称
   JobMeta jobMeta = new JobMeta(jobname, null);
   Job job = new Job(null, jobMeta);
   //向Job 脚本传递参数,脚本中获取参数值:${参数名}
   job.setVariable(paraname, paravalue);
   job.start();
   job.waitUntilFinished();
   if (job.getErrors() > 0) {
    System.out.println("decompress fail!");
   }
  } catch (KettleException e) {
   System.out.println(e);
  }
 }”
   调用Transformation示例:
“ public void runTrans(String filename) throws Exception {
    KettleEnvironment.init();
    TransMeta transMeta = new TransMeta(filename);
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    trans.startThreads();
    trans.waitUntilFinished();
    
    if (trans.getErrors()!=0) {
      System.out.println("Error");
    }
  }”                                                                   

 

来自于  http://kettleking.iteye.com/blog/1108451

 

java api调用 kettle job时,报如下异常

 

 

INFO  09-02 16:33:53,703 - Job1 - 开始执行任务
INFO  09-02 16:33:53,718 - Job1 - 开始项[Transformation]
ERROR 09-02 16:33:53,718 - Transformation - Unable to open transformation: null
ERROR 09-02 16:33:53,718 - Transformation - java.lang.NullPointerException
	at org.pentaho.di.job.entries.trans.JobEntryTrans.execute(JobEntryTrans.java:688)
	at org.pentaho.di.job.Job.execute(Job.java:503)
	at org.pentaho.di.job.Job.execute(Job.java:642)
	at org.pentaho.di.job.Job.execute(Job.java:368)
	at org.pentaho.di.job.Job.run(Job.java:288)

INFO  09-02 16:33:53,718 - Job1 - 完成作业项[Transformation] (结果=[false])
INFO  09-02 16:33:53,734 - Job1 - 任务执行完毕

 此异常一直未解决,还望用过的朋友回复一下。

你可能感兴趣的:(Kettle,etl)