简体   繁体   中英

Run Kettle transformation by java

I created a java app (pilot) to run a kettle transformation. It's very simple, I have only the main method, that get a .ktr file and execute this.

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.

   <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. 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. Else eclipse will throw exceptions.

Check the pentaho wiki and also this blog from me. I have used postgresql as a database connection. Try to modify the maven as per your database.

Hope it helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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