package com.kettle.test;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.util.EnvUtil;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
public class TransUtils {
//调用本地的转换文件(带参数)
public static void callNativeTransWithParam(String transFileName) {
// 初始化
try {
EnvUtil.environmentInit();
KettleEnvironment.init();
//kettle3.2以后下面这句就不要了
//StepLoader.init();
// 转换元对象
TransMeta transMeta = new TransMeta(transFileName);
// 转换
Trans trans = new Trans(transMeta);
String[] params = {};
// 执行转换
trans.execute(params);
// 等待转换执行结束
trans.waitUntilFinished();
} catch (KettleException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.kettle.test;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.job.Job;
import org.pentaho.di.job.JobMeta;
public class JobUtils {
//执行本地的任务文件
public static void callNativeJob(String jobFileName) {
try {
KettleEnvironment.init();
//jobname 是Job脚本的路径及名称
JobMeta jobMeta = new JobMeta(jobFileName, null);
Job job = new Job(null, jobMeta);
//向Job 脚本传递参数,脚本中获取参数值:${参数名}
//job.setVariable(null, null);
job.start();
job.waitUntilFinished();
if (job.getErrors() > 0) {
System.out.println("decompress fail!");
}
} catch (KettleException e) {
System.out.println(e);
}
}
}
package com.kettle.test;
public class Test {
/**
* @param args
* @throws KettleException
*/
public static void main(String[] args){
// TODO Auto-generated method stub
String JUPath="./file/201505111343.kjb";
String TUPath="./file/201505111306.ktr";
//TransUtils.callNativeTransWithParam(TUPath);
JobUtils.callNativeJob(JUPath);
System.out.println("wq vb !");
}
}
转载于:https://blog.51cto.com/xgqlovehy/1650391