简体   繁体   中英

Java App to run a Kettle Job and receive the result

可以从Java应用程序运行Kettle Job / Transformation ,然后在同一Java App中获取结果(例如变量)吗?

Although command line execution from Java likely isn't ideal, below would work. Just replace the cmd line with the appropriate paths and read in the output file of the job.

public static void main(String[] args) {

    try {
        String cmd = "\"c:\\Program Files\\Pentaho\\pdi-ce-5.0.1.A-stable\\data-integration\\kitchen.bat\" -file=\"c:\\users\\exampleuser\\desktop\\examplejob.kjb\"";
        System.out.println(cmd);
        Process process = Runtime.getRuntime().exec(cmd);
        process.waitFor();
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
    /*READ OUTPUT FILE OF KJB IN TO OBTAIN VALUES*/


}

* http://forums.pentaho.com/showthread.php?81151-Tutorial-Using-command-line-arguments-with-Kettle-and-scheduling * http://docs.oracle.com/javase/tutorial/java/data/strings.html * http://wiki.pentaho.com/display/EAI/.01+Introduction+to+Spoon * http://javarevisited.blogspot.com/2011/02/how-to-execute-native-shell-commands.html * http://www.mkyong.com/java/how-to-execute-shell-command-from-java/

I'd try this to execute the transformation this way . Kettle's Java API is quite readable.

The way described above does not cover retrieving the results. You'd need to add some custom logic to read the output data of the job. I'm not sure if there is a generic way to do that with ETL.

You can try grabbing the output into a HSQLDB or another in-memory DB, as described here , and extract the output manually.

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