kettlejava脚本的api_Java调用自己开发的Kettle plugin插件
反正找了一天天也沒找到!!! Kettle 6.1 相比 Kettle 3 改動太大了。下面直接上代碼,備忘!
在初始化
KettleEnvironment.init();
添加插件如下代碼,就能夠注冊一個Step的插件了
List empty = Collections.emptyList();
// 這個map別復用了,下一個插件重新new一個,不然即使clear了,下一個插件也不能注冊成功
Map,String> xxxxClassMap=new HashMap,String>();
// xxxxMeta 就是開發的插件的Meta類了
xxxxClassMap.put(StepMetaInterface.class,xxxxMeta.class.getName());
PluginInterface xxxxPlugin=new Plugin(
new String[]{"MergeField"},
StepPluginType.class,
StepMetaInterface.class,
"轉換",
"插件的名字",
"插件的描述,不影響java執行",
"插件的圖片,不影響java執行",
false,
false,
xxxxClassMap,
empty,
null,
null);
PluginRegistry.getInstance().registerPlugin(StepPluginType.class,xxxxPlugin);
Map,String> anotherClassMap=new HashMap,String>();
// anotherMeta 就是開發的插件的Meta類了
xxxxClassMap.put(StepMetaInterface.class,anotherMeta.class.getName());
PluginInterface anotherPlugin=new Plugin(
new String[]{"MergeField"},
StepPluginType.class,
StepMetaInterface.class,
"轉換",
"插件的名字",
"插件的描述,不影響java執行",
"插件的圖片,不影響java執行",
false,
false,
anotherClassMap,
empty,
null,
null);
PluginRegistry.getInstance().registerPlugin(StepPluginType.class,anotherPlugin);
如此這般就能運行了
附上java調用stepMeta的完整代碼
KettleEnvironment.init();
List empty = Collections.emptyList();
// 這個map別復用了,下一個插件重新new一個,不然即使clear了,下一個插件也不能注冊成功
Map,String> xxxxClassMap=new HashMap,String>();
// xxxxMeta 就是開發的插件的Meta類了
xxxxClassMap.put(StepMetaInterface.class,xxxxMeta.class.getName());
PluginInterface xxxxPlugin=new Plugin(
new String[]{"MergeField"},
StepPluginType.class,
StepMetaInterface.class,
"轉換",
"插件的名字",
"插件的描述,不影響java執行",
"插件的圖片,不影響java執行",
false,
false,
xxxxClassMap,
empty,
null,
null);
PluginRegistry.getInstance().registerPlugin(StepPluginType.class,xxxxPlugin);
// 數據庫連接元對象(連接名稱,不必與kettle中配置的保持一致:數據庫類型:連接方式(kettle支持的連接方式):資源庫IP:資源庫實例名:資源庫端口:資源庫用戶名:資源庫用戶密碼)
DatabaseMeta connection = new DatabaseMeta("資源庫名稱,不影響", "Oracle", DatabaseMeta.getAccessTypeDesc(0), "oracle的地址", "oracle的實例", "1521", "oracle用戶名", "oracle密碼");
// 資源庫元對象
KettleDatabaseRepositoryMeta repinfo = new KettleDatabaseRepositoryMeta();
repinfo.setConnection(connection);
// 資源庫
KettleDatabaseRepository repository = new KettleDatabaseRepository();
repository.init(repinfo);
// 連接資源庫
repository.connect("admin","admin",true);
// 資源庫目錄對象
RepositoryDirectoryInterface directoryInterface=repository.loadRepositoryDirectoryTree();
// 轉換元對象
TransMeta transMeta=repository.loadTransformation("tran的名稱",directoryInterface,null,true,null);
// 轉換
Trans trans = new Trans(transMeta);
// 執行轉換
trans.execute(null);
// 等待轉換執行結束
if(trans.getErrors()>0){
System.out.println("transformation error");
}else{
System.out.println("transformation successfully");
}
總結
以上是生活随笔為你收集整理的kettlejava脚本的api_Java调用自己开发的Kettle plugin插件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 工业机器人电路图讲解话术_燃气传感器技术
- 下一篇: python常用模块实例_python中