Springboot调用kettle9。3
Springboot调用kettle9.3
作业如下:
maven POM文件配置
commons-codec commons-codec 1.15 system ${kettle_project.dir}/lib/commons-codec-1.15.jar org.apache.commons commons-io 2.2 system ${kettle_project.dir}/lib/commons-io-2.2.jar com.google.common guava 17.0 system ${kettle_project.dir}/lib/guava-17.0.jar org.pentaho.di kettle-core 9.3.0 system ${kettle_project.dir}/lib/kettle-core-9.3.0.0-428.jar org.pentaho.di kettle-engine 9.3.0 system ${kettle_project.dir}/lib/kettle-engine-9.3.0.0-428.jar org.pentaho.metastore metastore 9.3.0 system ${kettle_project.dir}/lib/metastore-9.3.0.0-428.jar org.apache.commons commons-vfs2 2.7.0 system ${kettle_project.dir}/lib/commons-vfs2-2.7.0.jar org.pentaho pentaho-encryption-support 9.3.0.0-428 system ${kettle_project.dir}/lib/pentaho-encryption-support-9.3.0.0-428.jar net.sourceforge.jexcelapi jxl 2.6.12 system ${kettle_project.dir}/lib/jxl-2.6.12.jar commons-dbcp commons-dbcp 1.4 system ${kettle_project.dir}/lib/commons-dbcp-1.4.jar commons-pool commons-pool 1.5.7 system ${kettle_project.dir}/lib/commons-pool-1.5.7.jar
以上使用本地kettle中的包,本地kettle路径lib如下
导入kettle-password-encoder-plugins.xml文件,放在根目录之下,如图
Kettle Password Encoder org.pentaho.support.encryption.KettleTwoWayPasswordEncoder
Kettle工具类
作业路径
service
@Value("${kettle.script.path}") private String dirPath; public void runKtr(String trans_name){ try{ KettleEnvironment.init(); TransMeta transMeta=new TransMeta(dirPath+trans_name+".ktr"); Trans trans=new Trans(transMeta); trans.execute(null); trans.waitUntilFinished(); //System.out.println("---------dzz"); }catch(KettleException e){ e.printStackTrace(); } } public void runKjb(String job_name,Map params){ try{ KettleEnvironment.init(); JobMeta jm=new JobMeta(dirPath+job_name+".kjb",null); Job job=new Job(null,jm); if(params!=null){ Iterator> entries=params.entrySet().iterator(); while(entries.hasNext()){ Map.Entry entry=entries.next(); job.setVariable(entry.getKey(),entry.getValue());//设置变量 //job.setParameterValue(entry.getKey(),entry.getValue()); //System.out.println("------1---dzz--"+entry.toString()); } } job.start(); //Result result=new Result(); //job.execute(0,result); job.waitUntilFinished(); //System.out.println("------result---dzz"+result.toString()); }catch(KettleException e){ e.printStackTrace(); } }
controller
内容如下 //------------------------------------------- @ResponseBody @RequestMapping("/toKettle/trans/{trans_name}") public String toKettle_tran(@PathVariable("trans_name") String trans_name) { kettleservice.runKtr(trans_name); return "kettle trans finished"; } @ResponseBody @RequestMapping("/toKettle/job/{job_name}") public String toKettle_job(@PathVariable("job_name") String job_name) { Map map=new HashMap(); map.put("filename","结算主单11"); //map.put("filename2","结算主单22"); kettleservice.runKjb(job_name,map); return "kettle job finished"; }
执行
2023-2-8