Hitachi Vantara Pentaho Community Forums
Results 1 to 9 of 9

Thread: execute Job from Java

  1. #1
    Join Date
    Sep 2010
    Posts
    133

    Default execute Job from Java

    Hi.
    How can I execute jobs from Java???

    Thank you

  2. #2
    Join Date
    Feb 2008
    Posts
    107

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

    Default

    OK, this is the example found in Pentaho Kettle Solutions. For the explanations I guess you have to read the book (Chapter 22):

    Code:
    package example.ch22;
    
    import org.pentaho.di.core.KettleEnvironment;
    import org.pentaho.di.job.Job;
    import org.pentaho.di.job.JobMeta;
    
    public class ExecuteJob {
      public static void main(String[] args) throws Exception {
        String filename = args[0];
        
        KettleEnvironment.init();
        
        JobMeta jobMeta = new JobMeta(filename, null);
        Job job = new Job(null, jobMeta);
        job.start();
        job.waitUntilFinished();
        
        if (job.getErrors()!=0) {
          System.out.println("Error encountered!");
        }
      }
    }
    Source

  4. #4
    Join Date
    Sep 2010
    Posts
    133

    Default

    Ok thank you very much, it works
    Another question:what's the difference between the object "Job" and the object "JobMeta" ???

    Thanks!!

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

    Default

    JobMeta --> The job ETL metadata (definition)
    Job --> The job metadata execution engine.

  6. #6
    Join Date
    Sep 2010
    Posts
    133

    Default

    Ok.
    But I executed my job from Eclipse and it works...
    I set 1 parameter in the job(by spoon) but I can see it only with the object JobMeta and not with Job...why???
    Calling getParameters with JobMeta I have the right result set; with Job "null"...Why??

  7. #7

    Default

    I have the book, so I'm going to go read that appropriate section now, but I have a question. Is there a way, from within the API, to call jobs with arguments similar to the command line. For example, this example requires that there is a filename path to the job. On the command line I need only specify the repo and job user pass etc.

  8. #8
    Join Date
    Jan 2017
    Posts
    1

    Default

    Hi Matt,

    I used the above sample to execute a job using java. apparently there are wrong DB connections to persist data the code doesn'y give any exceptions. when i run it through UI tool (spoon) it throws exception. wht i am missing ?

  9. #9

    Default

    Quote Originally Posted by thusira View Post
    Hi Matt,

    I used the above sample to execute a job using java. apparently there are wrong DB connections to persist data the code doesn'y give any exceptions. when i run it through UI tool (spoon) it throws exception. wht i am missing ?

    job.getLogText() will give you the exception you are looking for. Play with the job object.

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.