简体   繁体   English

用Java运行Kettle转换

[英]Run Kettle transformation by java

I created a java app (pilot) to run a kettle transformation. 我创建了一个Java应用程序(飞行员)来运行水壶转换。 It's very simple, I have only the main method, that get a .ktr file and execute this. 这很简单,我只有main方法,可以获取.ktr文件并执行该方法。

public static void main( String[] args )
    {
        try {
            KettleEnvironment.init();
            TransMeta transMeta = new TransMeta("C:\\user\\car.ktr");
            Trans trans = new Trans(transMeta); //create new transformation object
            trans.execute(null);
            trans.waitUntilFinished();
        } catch (KettleException e) {
            e.printStackTrace();
        }
    }

The problem is that when I run this, I get an exception. 问题是,当我运行此命令时,出现异常。

2014/12/23 08:24:54 - Table output.0 - ERROR (version 5.0.5, build 1 from 2014-03-21_17-56-23 by buildguy) : Error initializing step [Table output]
2014/12/23 08:24:54 - Table output.0 - ERROR (version 5.0.5, build 1 from 2014-03-21_17-56-23 by buildguy) : java.lang.AbstractMethodError
2014/12/23 08:24:54 - Table output.0 -  at org.pentaho.di.core.logging.LoggingObject.grabLoggingObjectInformation(LoggingObject.java:136)
2014/12/23 08:24:54 - Table output.0 -  at org.pentaho.di.core.logging.LoggingObject.<init>(LoggingObject.java:56)
2014/12/23 08:24:54 - Table output.0 -  at org.pentaho.di.core.logging.LoggingRegistry.registerLoggingSource(LoggingRegistry.java:70)
2014/12/23 08:24:54 - Table output.0 -  at org.pentaho.di.core.logging.LogChannel.<init>(LogChannel.java:74)
2014/12/23 08:24:54 - Table output.0 -  at org.pentaho.di.core.database.Database.<init>(Database.java:191)
2014/12/23 08:24:54 - Table output.0 -  at org.pentaho.di.trans.steps.tableoutput.TableOutput.init(TableOutput.java:598)
2014/12/23 08:24:54 - Table output.0 -  at org.pentaho.di.trans.step.StepInitThread.run(StepInitThread.java:65)
2014/12/23 08:24:54 - Table output.0 -  at java.lang.Thread.run(Unknown Source)
2014/12/23 08:24:54 - car - ERROR (version 5.0.5, build 1 from 2014-03-21_17-56-23 by buildguy) : Step [Table output.0] failed to initialize!
org.pentaho.di.core.exception.KettleException: 
We failed to initialize at least one step.  Execution can not begin!


    at org.pentaho.di.trans.Trans.prepareExecution(Trans.java:1068)
    at org.pentaho.di.trans.Trans.execute(Trans.java:578)
    at neoway.com.App.main(App.java:16)

It created this app with maven, and I have these dependencies. 它使用maven创建了此应用,而我具有这些依赖关系。

   <dependency>
      <groupId>pentaho-kettle</groupId>
      <artifactId>kettle-engine</artifactId>
      <version>5.0.5</version>
   </dependency>
   <dependency>
      <groupId>pentaho-kettle</groupId>
      <artifactId>kettle-db</artifactId>
      <version>4.4.3.3</version>
   </dependency>
   <dependency>
      <groupId>pentaho-kettle</groupId>
      <artifactId>kettle-core</artifactId>
      <version>5.0.5</version>
   </dependency>
   <dependency>
      <groupId>pentaho-kettle</groupId>
      <artifactId>kettle-ui-swt</artifactId>
      <version>5.0.5</version>
   </dependency>
   <dependency>
      <groupId>pentaho-library</groupId>
      <artifactId>libformula</artifactId>
      <version>5.0.5</version>
   </dependency>

Anybody have any idea about the problem? 有人对这个问题有任何想法吗?

Thanks. 谢谢。

You need to also add your database dependency in the pom.xml file. 您还需要在pom.xml文件中添加数据库依赖项。 Since your transformation (the one which you are executing) is having a database connectivity, you need to import the corresponding jar to the eclipse workspace. 由于您的转换(正在执行的转换)具有数据库连接性,因此需要将相应的jar导入eclipse工作空间。 Else eclipse will throw exceptions. 否则,日食将引发异常。

Check the pentaho wiki and also this blog from me. 检查Pentaho的维基 ,也从我博客。 I have used postgresql as a database connection. 我已经使用postgresql作为数据库连接。 Try to modify the maven as per your database. 尝试根据数据库修改Maven。

Hope it helps :) 希望能帮助到你 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM