Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: need invoke java from kettle

  1. #1
    Join Date
    Apr 2009
    Posts
    6

    Red face need invoke java from kettle

    Hi All,
    I just want to invoke java class via kettle application. i cant find and correct samples till now.
    can anyone help me with better sample..

    Thanks,

  2. #2
    Join Date
    Sep 2007
    Posts
    834

    Default

    Use a Modified Java Script Step. You have to place the following line of code on top of your javascript:
    java
    Then you can use access all the java objects that are in Kettle's classpath.

  3. #3
    Join Date
    Apr 2009
    Posts
    6

    Smile

    thanks Maria,
    i have created the jar file with the java class, and i placed in \libext folder.

    My java class:
    package com.ps;

    import org.pentaho.di.core.exception.KettleException;
    import org.pentaho.di.core.logging.LogWriter;
    import org.pentaho.di.job.Job;
    import org.pentaho.di.job.JobEntryLoader;
    import org.pentaho.di.job.JobMeta;
    import org.pentaho.di.trans.StepLoader;

    public class Mainjob {
    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    LogWriter logWriter = null;
    try {

    String filename = "C:\\Files\\Current\\Source File\\Today\\Multi_job.kjb";
    StepLoader.init();
    JobEntryLoader.init();
    logWriter = LogWriter.getInstance(LogWriter.LOG_LEVEL_BASIC);
    JobMeta jobMeta = new JobMeta(logWriter, filename.toString(), null);
    Job job = new Job(logWriter, null, jobMeta);
    job.execute();
    job.waitUntilFinished();
    if (job.getErrors() > 0) {
    throw new RuntimeException(
    "There were errors during transformation execution.");
    }
    } catch (KettleException e) {
    // TODO Put your exception-handling code here.
    System.out.println(e);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    In my kettle java script:

    java;

    Packages.MainJob.main(null);

    true;

    In spoon bat file i have updated as:

    set CLASSPATH=%CLASSPATH%;E:\Share\ps\Offictial\Workspace_1\Kettle1\bin\com\ps


    but when i run my java script, i am getting this error

    2009/06/26 10:13:20 - Trans - This transformation can be replayed with replay date: 2009/06/26 10:13:20
    2009/06/26 10:13:20 - ## TEST DATA ##.0 - Finished processing (I=0, O=0, R=0, W=10, U=0, E=0)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : Unexpected error :
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : org.pentaho.di.core.exception.KettleValueException:
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : Javascript error:
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : TypeError: Cannot call property main in object [JavaPackage MainJob]. It is not a function, it is "object". (script#5)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) :
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.addValues(ScriptValuesMod.java:436)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.processRow(ScriptValuesMod.java:667)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.pentaho.di.trans.step.BaseStep.runStepThread(BaseStep.java:2861)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.run(ScriptValuesMod.java:730)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot call property main in object [JavaPackage MainJob]. It is not a function, it is "object". (script#5)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3557)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3563)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.mozilla.javascript.ScriptRuntime.typeError3(ScriptRuntime.java:3589)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3649)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2186)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.mozilla.javascript.gen.c1._c0(script:5)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.mozilla.javascript.gen.c1.call(script)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.mozilla.javascript.gen.c1.call(script)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.mozilla.javascript.gen.c1.exec(script)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.addValues(ScriptValuesMod.java:355)
    2009/06/26 10:13:20 - Modified Java Script Value.0 - ERROR (version 3.2.0-RC1, build 10435 from 2009-03-20 09.51.14 by buildguy) : ... 3 more
    2009/06/26 10:13:20 - Modified Java Script Value.0 - Finished processing (I=0, O=0, R=1, W=0, U=0, E=1)
    2009/06/26 10:13:20 - Kettle - Transformation detected one or more steps with errors.
    2009/06/26 10:13:20 - Kettle - Transformation is killing the other steps!

    can u help me....
    Last edited by gowri; 06-26-2009 at 12:47 AM.

  4. #4
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    Hey, this has come up many many (many) times already. Why don't you search the forum a bit?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.