1. Java代码中传递参数:代码
public static void runJob(StringjobFilePath,Map<String, String> paramMap) {
try{
EnvUtil.environmentInit();
JobEntryLoader.init();
StepLoader.init();
LogWriterlog = LogWriter.getInstance("D:/logs/ts_logs/kettle.log", true,LogWriter.LOG_LEVEL_BASIC);
JobMetajobMeta = new JobMeta(log, jobFilePath,
null);
Jobjob = new Job(log,
StepLoader.getInstance(),null, jobMeta);
job.getJobMeta().setInternalKettleVariables(job);
//給job传递参数
if(paramMap!=null&& paramMap.size()>0){
for(Stringkey:paramMap.keySet()){
job.setVariable(key,paramMap.get(key));
}
}
job.execute();// You can pass arguments instead of null.
job.waitUntilFinished();
if(job.getErrors() > 0) {
thrownew RuntimeException(
"Therewere errors during transformation execution.");
}
}catch (KettleException e) {
System.out.println(e);
}
}
2. job中获取参数:采用${}形式获取参数
3. 在trans中获取参数: