分享

java 调用kettle 6.1 转换

释怀 发表于 2016-9-28 16:28:27 [显示全部楼层] 只看大图 回帖奖励 阅读模式 关闭右栏 3 24897
有人用过java 调用kettle6.1 转换脚本吗?       我用同样的代码,可以执行kettle 4.1的脚本,可6.1始终不行? 是6.1 不支持了?还是写法变了?

    如下这段代码4.1可以,6.1就不行。求解!!
    public static void call(String transFileName, String[] params) throws IOException {
                try {
                        // 初始化
                        KettleEnvironment.init();
                        // 转换元对象
                        TransMeta transMeta = new TransMeta(transFileName);
                        // 转换对象
                        Trans trans = new Trans(transMeta);
                        // 设置日志等级(debug非常详细,对于跟踪问题有帮助)
                        // trans.setLogLevel(LogLevel.DEBUG);
                        // trans.setLogLevel(LogLevel.ROWLEVEL);
                        // 传递参数
                        // 执行转换准备执行
                        trans.prepareExecution(params);
                        // 开启线程并执行
                        trans.startThreads();
                        // 直接执行(需要传入参数,如果使用该方法。可以不是用prepareExecution。)
                        // trans.execute(params);

                        Result result = trans.getResult();
                        System.out.println(result.getXML());
                        // trans.execute(params);
                        // 等待线程结束
                        trans.waitUntilFinished();
                        if (trans.getErrors() != 0) {
                                System.out.println("执行转换错误!");
                        }
                } catch (KettleException ke) {
                        ke.printStackTrace();
                }
        }


已有(3)人评论

跳转到指定楼层
tntzbzc 发表于 2016-9-28 17:05:03
关于6.1格式,楼主可参考这个
Java调用自定义开发的Kettle 6.1 plugin插件


回复

使用道具 举报

daoke_li 发表于 2016-10-9 12:49:31
本帖最后由 daoke_li 于 2016-10-9 12:54 编辑

java调用kettle6.1,代码:

public class kettle_test {

        public static void main(String[] args) throws KettleException {
               
        //初始化环境
        KettleEnvironment.init();
        //创建DB资源库
        KettleDatabaseRepository repository=new KettleDatabaseRepository();
        DatabaseMeta databaseMeta=new DatabaseMeta("Kettle_MySQL","mysql","jdbc","localhost","kettle_java","3306","name","password");
        //选择资源库
        KettleDatabaseRepositoryMeta kettleDatabaseRepositoryMeta=new KettleDatabaseRepositoryMeta("Kettle","Kettle","Transformation description",databaseMeta);
        repository.init(kettleDatabaseRepositoryMeta);
        //连接资源库
        repository.connect("admin","admin");
        RepositoryDirectoryInterface directoryInterface=repository.loadRepositoryDirectoryTree();
        //选择转换
        TransMeta transMeta=repository.loadTransformation("study05-01",directoryInterface,null,true,null);
        Trans trans=new Trans(transMeta);
        trans.execute(null);
        trans.waitUntilFinished();//等待直到数据结束
        if(trans.getErrors()>0){
            System.out.println("transformation error");
        }else{
            System.out.println("transformation successfully");
        }

        }

}

需要的jar包

需要的jar包
回复

使用道具 举报

释怀 发表于 2016-10-10 16:25:04
daoke_li 发表于 2016-10-9 12:49
java调用kettle6.1,代码:

public class kettle_test {

还是报错:

Exception in thread "main" org.pentaho.di.core.exception.KettleException:
Error connecting to the repository!


The version of the repository is -1.-1.
This Kettle edition requires it to be at least version 5.0 and as such an upgrade is required.

To upgrade, backup your database and export the repository to XML for additional safety.

Then select the 'Edit' button followed by the 'Create or Upgrade' button.

Please consult the Upgrade Guide for eventually special instructions for this version.


        at org.pentaho.di.repository.kdr.delegates.KettleDatabaseRepositoryConnectionDelegate.connect(KettleDatabaseRepositoryConnectionDelegate.java:160)
        at org.pentaho.di.repository.kdr.KettleDatabaseRepository.connect(KettleDatabaseRepository.java:191)
        at org.pentaho.di.repository.kdr.KettleDatabaseRepository.connect(KettleDatabaseRepository.java:180)
        at com.kettle.controller.Kettle_test.main(Kettle_test.java:34)
Caused by: org.pentaho.di.core.exception.KettleException:

The version of the repository is -1.-1.
This Kettle edition requires it to be at least version 5.0 and as such an upgrade is required.

To upgrade, backup your database and export the repository to XML for additional safety.

Then select the 'Edit' button followed by the 'Create or Upgrade' button.

Please consult the Upgrade Guide for eventually special instructions for this version.

        at org.pentaho.di.repository.kdr.delegates.KettleDatabaseRepositoryConnectionDelegate.verifyVersion(KettleDatabaseRepositoryConnectionDelegate.java:219)
        at org.pentaho.di.repository.kdr.delegates.KettleDatabaseRepositoryConnectionDelegate.connect(KettleDatabaseRepositoryConnectionDelegate.java:146)
        ... 3 more


补充:  我自己重新创建的资源库,但没有创建成功

The version of the repository is -1.-1.
This Kettle edition requires it to be at least version 5.0 and as such an upgrade is required.

To upgrade, backup your database and export the repository to XML for additional safety.

Then select the 'Edit' button followed by the 'Create or Upgrade' button.

Please consult the Upgrade Guide for eventually special instructions for this version



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条