-
package com.p.serv.util;
-
-
import org.pentaho.di.core.KettleEnvironment;
-
import org.pentaho.di.core.exception.KettleException;
-
import org.pentaho.di.core.exception.KettleXMLException;
-
import org.pentaho.di.job.Job;
-
import org.pentaho.di.job.JobMeta;
-
import org.pentaho.di.trans.Trans;
-
import org.pentaho.di.trans.TransMeta;
-
-
public class KettleExecu {
-
-
public static void runJob(String jobname) {
-
try {
-
KettleEnvironment.init();
-
-
JobMeta jobMeta = new JobMeta(jobname, null);
-
Job job = new Job(null, jobMeta);
-
-
-
job.start();
-
job.waitUntilFinished();
-
if (job.getErrors() > 0) {
-
System.out.println("decompress fail!");
-
}
-
} catch (KettleException e) {
-
System.out.println(e);
-
}
-
}
-
-
-
public static void runTrans(String filename) {
-
try {
-
KettleEnvironment.init();
-
TransMeta transMeta = new TransMeta(filename);
-
Trans trans = new Trans(transMeta);
-
trans.prepareExecution(null);
-
trans.startThreads();
-
trans.waitUntilFinished();
-
if (trans.getErrors() != 0) {
-
System.out.println("Error");
-
}
-
} catch (KettleXMLException e) {
-
-
e.printStackTrace();
-
} catch (KettleException e) {
-
-
e.printStackTrace();
-
}
-
}
-
-
public static void main(String[] args) {
-
String jobname = "F:\\ETL\\kettle\\例子\\测试\\复制多表\\copymanytablejob.kjb";
-
runJob(jobname);
-
-
-
}
-
-
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/76103/viewspace-2140269/
,如需转载,请注明出处,否则将追究法律责任。